如何解决Python 神经网络:类型错误:异常必须从 BaseException 派生
我想用 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]
我不知道这有什么问题,我什至不使用异常代码。 如果你有这个问题的解决方案,请帮我解决这个问题。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。