我有以下代碼:掩蔽選擇後一個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 ]
你可以發佈一個最小版本的'獨角獸',可以用來重現問題嗎? –