你如何在numpy的屏蔽数组蒙面的行数? [英] How do you get the number of masked rows in a numpy masked array?
问题描述
所以我有一个包含一些numpy的阵列,其中有的已经掩盖值,看起来像下面的一个numpy的数组:
So I have a numpy array that contains a number of numpy arrays where some of them have masked values that looks like the one below:
[[1 2 3]
[-- -- --]
[7 8 9]]
什么是最有效的方式来获得(意味着像[ - - - ])掩蔽numpy的阵列的数目越大numpy的阵列中(在这种情况下,这将是1)
What is the most efficient way to get the number of masked numpy arrays (meaning something like [-- -- --]) in the bigger numpy array (in this case it would be 1).
感谢您!
推荐答案
的蒙面阵列具有 .mask
属性包括布尔数组是真
地方值被屏蔽。如果你想知道多少行包含的至少一个的屏蔽值,可以使用:
Masked arrays have a .mask
attribute consisting of a boolean array that is True
wherever a value is masked. If you want to know how many rows contained at least one masked value, you could use:
x.mask.any(axis=1).sum()
其中, X
是蒙面的数组。如果你只对感兴趣的行,其中的所有的值被屏蔽,你可以使用:
where x
is your masked array. If you are only interested in rows where all of the values are masked, you could use:
x.mask.all(axis=1).sum()
显然,在你的榜样,这些都将给予1的结果。
Obviously in your example these would both give a result of 1.
这篇关于你如何在numpy的屏蔽数组蒙面的行数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!