我想从屏蔽数组中删除列,其中列中的每个值都被屏蔽。所以在下面的例子中:
>>> 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() 应该是什么才能获得给定的输出?
您可以使用花哨的索引:
test[:, ~np.all(test.mask, axis=0)]
#masked_array(data =
# [[1 --]
# [-- 3]
# [1 4]],
# mask =
# [[False True]
# [ True False]
# [False False]],
# fill_value = 0)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)