Python神经网络:TypeError:异常必须派生自BaseException

Python神经网络:TypeError:异常必须派生自BaseException,python,neural-network,spyder,Python,Neural Network,Spyder,我想用python来训练我的神经网络案例,我试图解决一些问题,但我发现了一个问题 控制台代码如下所示: @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

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

控制台代码如下所示:

@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]

原始代码如下所示:

@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]
@staticmethod
def colSpec(nparray:'np.ndarray',rangeStr:str=None,batchStart:str=None,batchEnd:str=None)->'np.ndarray':
'''
通过选择某些列或数据的批处理行来指定某些列数据。--更新(Dexter)20181210
参数
------------------------------
nparray`np.ndarray`-要选择的数据表。
rangeStr`str`-用于为转换选择特定列的索引范围字符串。
batchStart`int`-数据行的起始索引(包括)。
batchEnd`int`-数据行的结束索引(独占)。
退换商品
------------------------------
`np.ndarray`-具有请求的选择范围的数据表。
'''
#如果不是np数组,则转换为np数组。
如果不存在(nparray,np.ndarray):
如果存在(n阵列,列表):
尝试:
nparray=np.array(nparray)
除:
raise VALUERROR(“colSpec不支持数据类型。它应该是`np.ndarray`对象。”)
其他:
raise VALUERROR(“colSpec不支持数据类型。它应该是`np.ndarray`对象。”)
#如果没有请求列规范,只需返回包含batchStart和batchEnd行的原始数组。
如果rangeStr为无:
返回nparray[batchStart:batchEnd]
其他:
colCount=len(nparray[0])
#验证索引范围。
如果(不是IndexRange.validate(colCount,rangeStr)):
raise VALUERROR(“索引范围字符串无效”)
#列选择上的不同场景:
如果在rangeStr中为“:”:
#拆分“:”以查找范围开始和结束。
rangeInfo=[string.strip()表示rangeStr.split(“:”)中的字符串
#不应为2值元组指定任何值。
如果有([(对于rangeInfo中的ele,ele==“无”或ele==”)):
#确定未使用的场景。
如果rangeInfo[0]!=“无”和len(rangeInfo[0]):
返回nparray[batchStart:batchEnd,int(rangeInfo[0]):]
elif rangeInfo[1]!=“无”和len(rangeInfo[1]):
返回nparray[batchStart:batchEnd,:int(rangeInfo[1])]
其他:
返回nparray[batchStart:batchEnd]
其他:
raise nparray[batchStart:batchEnd,int(rangeInfo[0]):int(rangeInfo[1])]
#否则,它将显式指定索引。
其他:
idxs=IndexRange.parse(colCount,rangeStr)
返回nparray[batchStart:batchEnd,idxs]
我不知道这有什么不对,我甚至不使用异常代码。
如果您有此问题的解决方案,请帮助我解决此问题。

仔细查看您的代码,特别是
NeuralSimplycode.py
中的第2890行。在这一行你想干什么?(提示:在我看来这像是一个输入错误;))您只能
引发
异常,而不是numpy数组。你是说
返回