[英]Iterate over numpy.ma array, ignoring masked values
I would like to iterate over only unmasked values in a np.ma.ndarray
. 我只想遍历np.ma.ndarray
未屏蔽值。
With the following: 具有以下内容:
import numpy as np
a = np.ma.array([1, 2, 3], mask = [0, 1, 0])
for i in a:
print i
I get: 我得到:
1
--
3
I would like to get the following: 我想得到以下内容:
1
3
It seems like np.nditer()
may be the way to go, but I don't find any flags that might specify this. 似乎np.nditer()
可能是要解决的办法,但我找不到任何可以指定此标志的标志 。 How might I do this? 我该怎么办? Thanks! 谢谢!
you want to use a.compressed()
您想使用a.compressed()
import numpy as np
a = np.ma.array([1, 2, 3], mask = [0, 1, 0])
for i in a.compressed():
print i
which gives: 这使:
1
3
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.