Python 神经网络:类型错误:异常必须从 BaseException 派生

问题描述

我想用 python 来训练我的神经网络案例,我试图解决一些问题,但我发现了一个问题。

控制台代码如下所示:

enter image description here

原来的代码是这样的:

@staticmethod
def colSpec(nparray: 'np.ndarray',rangeStr:str=None,batchStart:str=None,batchEnd:str=None)->'np.ndarray':
    '''
        Specify certain column data by selecting some columns or batched rows of data.   --- UPDATED (Dexter) 20181210

        Parameters
        ------------------------------

        nparray     `np.ndarray<np.array<(int|float|str)>>`   - Data table to be selected.

        rangeStr    `str`   - Index range string for selecting certain columns for the transformation.

        batchStart  `int`   - The starting index (inclusive) of the data rows.

        batchEnd    `int`   - The ending index (exclusive) of the data rows.

        Returns
        ------------------------------

        `np.ndarray<np.array<(int|float|str)>>`   - Data table with requested selection range.
    '''
    # Convert to np array if it's not.
    if not isinstance(nparray,np.ndarray):
        if isinstance(nparray,list):
            try:
                nparray = np.array(nparray)
            except:
                raise ValueError("Data type not supported for colSpec. It should be an `np.ndarray` object.")
        else:
            raise ValueError("Data type not supported for colSpec. It should be an `np.ndarray` object.")

    # If no column specification requested,just return the orginal array with batchStart and batchEnd rows.
    if rangeStr is None:
        return nparray[batchStart:batchEnd]
    
    else:
        colCount = len(nparray[0])

        # Validate the index range range.
        if (not Indexrange.validate(colCount,rangeStr)):
            raise ValueError("Index range string is not valid.")

        # Different scenarios on the column selections:
        if ":" in rangeStr:
            # Split the ":" to find the range start and end.
            rangeInfo = [string.strip() for string in rangeStr.split(":")]

            # None should be specified for 2-valued tuples.
            if any([(ele == "None" or ele == "") for ele in rangeInfo]):
                # Determine the scenarios for which None is used.
                if rangeInfo[0] != "None" and len(rangeInfo[0]):
                    return nparray[batchStart:batchEnd,int(rangeInfo[0]):]
                elif rangeInfo[1] != "None" and len(rangeInfo[1]):
                    return nparray[batchStart:batchEnd,:int(rangeInfo[1])]
                else:
                    return nparray[batchStart:batchEnd]
            else:
                raise nparray[batchStart:batchEnd,int(rangeInfo[0]):int(rangeInfo[1])]
        
        # Otherwise,it is specifying indexes explicitly. 
        else:
            idxs = Indexrange.parse(colCount,rangeStr)
            return nparray[batchStart:batchEnd,idxs]

我不知道这有什么问题,我什至不使用异常代码。 如果你有这个问题的解决方案,请帮我解决这个问题。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...