【发布时间】:2013-04-03 04:33:27
【问题描述】:
我有以下数组:
[[ 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。 -
那会怎样,我该怎么做?