索引错误:布尔索引在维度1上与索引数组不匹配;维度为3但相应的布尔维度为10

2024-04-19 08:54:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我应该如何修正这个错误?

dhidden[hidden <= 0] = 0

给我一个错误:

IndexError: boolean index did not match indexed array along dimension 1; dimension is 3 but corresponding boolean dimension is 10

更多信息:

 print(type(hidden))
<class 'numpy.ndarray'>
 print(type(hidden))

<class 'numpy.ndarray'> 
print(dhidden.shape)
(5, 3)
 print(hidden.shape)
(5, 10)

hidden.dtype和dhidden.dtype是float64

我尝试了dhidden[hidden<;=0.0]=0.0,仍然得到相同的错误。


Tags: numpyindexistype错误hiddenclassprint