我有以下的數組:試圖掩蓋基於值2D numpy的陣列中的一列
[[ 6. 105. 2. 8.09841881]
[ 6. 105. 4. 9.34220351]
[ 6. 105. 6. 9.97663435]
[ 6. 1001. 2. 9.57108242]
[ 6. 1001. 4. 12.22355794]
[ 6. 1001. 6. 13.57295942]
[ 12. 1001. 2. 12.37474466]
[ 12. 1001. 4. 17.45334004]
[ 12. 1001. 6. 19.88499289]
[ 18. 1007. 2. 16.09076561]
[ 18. 1007. 4. 23.43742275]
[ 18. 1007. 6. 27.73041646]]
我試圖僅提取與所述第一元件是一個六經由
print ma.MaskedArray(a, mask=(np.ones_like(a)*(a[:,0]==6.0)).T)
行
我從問題「mask a 2D numpy array based on values in one column」得到。然而,我得到
File "./Prova.py", line 170, in <module>
print ma.MaskedArray(a, mask=(np.ones_like(a)*(a[:,0]==6.0)).T)
ValueError: operands could not be broadcast together with shapes (12,4) (12)
你有線索爲什麼這不起作用?
這個問題可能是愚蠢的,但請自我承擔,因爲我剛開始編程python。 :-)
您可能需要在您的掩碼中插入一個'np.newaxis'。 – mgilson
這樣做會怎樣,我該怎麼做? –