我有以下代码:掩蔽选择后一个numpy的阵列与非numpy的阵列
# unicorns is a numpy array with several fields
idx = (1, 2, 3, 5, 7)
unicorns=uni[idx]
# now i have only the first, second, third, ... unicorn
print unicorns
但是如果我想的子查询这个麒麟阵列
unicorns['color'=='white']['Name']
应该给我的名字的白色独角兽,numpy只将 的color==white
部分解释为False
,它会变为0,它会返回我的数组的第一个条目。
我该如何解决这个问题,以便它能做到我想要的,选择白色的独角兽?
我宁愿一切都保持为numpy,所以我也可以选择独角兽的其他属性。
编辑
下面是数组的例子:
unicorns=[(1, black, 0.0, 'Pinky', 1) (2, black, 0.0, 'Winky', 1)
(3, white, 0.0, 'Lala', 1) (4, white, 0.0, 'Merlin', 1)
(5, black, 0.0, 'Meriva', 1) (6, white, 0.0, 'Panda', 1)]
idx = [ 0 , 3 , 6 ]
你可以发布一个最小版本的'独角兽',可以用来重现问题吗? –