我有以下数组:
[[ 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)
我从问题“根据一列中的值屏蔽 2D numpy 数组”得到。但是,我得到
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,请多多包涵。:-)