[已解决]IndexError: too many indices for array: array is 2-dimensional, but 3 were indexed 或IndexError: boolean index did not match indexed array along dimension 1
问题描述:
试图用布尔向量y,挑选对应的x。numpy报错如上
y.shape
(100, 1)
x.shape
(100, 3)
解决方案
由于x[y == 1],x[y == 1, -2]这类操作的y只允许是向量(只允许有一个维度)
即y.shape (100,)
这一类
进行该操作即可↓
y=np.squeeze(y)
解决效果如下图