【发布时间】:2019-10-30 03:28:43
【问题描述】:
我有一个 130 X 13 的 numpy 矩阵。假设我想选择一组满足条件的特定行和一组列 -
trainx[trainy==label,[0,6]]
以上代码不起作用并抛出错误-IndexError: shape mismatch: indexing arrays could not be broadcast together with shapes (43,) (2,).
但是,如果我分两步进行 - 首先是子集行,然后是列,它可以工作。是不是有些奇怪或 numpy 以这种方式工作?
temp1 = trainx[trainy==label,:]
temp1 = temp1[:,[0,6]]
【问题讨论】:
-
trains.loc[...,...] ?
-
两步索引可能是最容易理解和使用的,尤其是当行索引是布尔掩码时..
-
我假设
trainy是 (130,) 形状,对吧?