微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决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.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?