删除所有值都被屏蔽的列 [英] Remove columns where every value is masked
本文介绍了删除所有值都被屏蔽的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从掩码数组中删除列,其中该列中的每个值都被掩码.因此,在以下示例中:
I want to remove columns from a masked array where every value in the column is masked. So in the following example:
>>> import numpy as np
>>> test = np.array([[1,0,0],[0,3,0],[1,4,0]])
>>> test = np.ma.masked_equal(test,0)
>>> test
[[1 -- --]
[-- 3 --]
[1 4 --]],
>>> np.somefunction(test)
[[1 --]
[-- 3 ]
[1 4 ]]
np.somefunction() 应该是什么来获得给定的输出?
what should np.somefunction() be to get the given output?
推荐答案
您可以使用花式索引:
test[:, ~np.all(test.mask, axis=0)]
#masked_array(data =
# [[1 --]
# [-- 3]
# [1 4]],
# mask =
# [[False True]
# [ True False]
# [False False]],
# fill_value = 0)
这篇关于删除所有值都被屏蔽的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文