我有以下的数组:试图掩盖基于值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
这样做会怎样,我该怎么做? –