IndexError:形状不匹配:索引数组不能与形状一起广播(2,)(9,)

时间:2017-02-07 10:13:15

标签: python arrays numpy numpy-broadcasting

在这部分代码中:

for k, v in Candidates.iteritems():
        Device = XDevice[XDevice[:, 1] == k, np.array([2, 3, 4, 5, 6, 7, 8, 9, 10])]

我有这个IndexError:

shape mismatch: indexing arrays could not be broadcast together with shapes (2,) (9,) 

1 个答案:

答案 0 :(得分:0)

好像你不能同时在两个维度上进行选择!

将它分成两行:

for k, v in Candidates.iteritems():
        Device_ = XDevice[XDevice[:, 1] == k,:]
        Device =  Device_[:,np.array([2, 3, 4, 5, 6, 7, 8, 9, 10])