对于Python中的2D掩码数组,获得包含非掩码值的第一行和最后一列的索引的最佳方法是什么?在
import numpy as np
a = np.reshape(range(30), (6,5))
amask = np.array([[True, True, False, True, True],
[True, False, False, True, True],
[True, True, True, False, True],
[True, False, False, False, True],
[True, True, True, False, True],
[True, True, True, True, True]])
a = np.ma.masked_array(a, amask)
print a
# [[-- -- 2 -- --]
# [-- 6 7 -- --]
# [-- -- -- 13 --]
# [-- 16 17 18 --]
# [-- -- -- 23 --]
# [-- -- -- -- --]]
在本例中,我想获得:
(0, 4)
用于轴0(因为第一行无掩码值是0,最后一行是4;第6行(第5行)只包含掩码值)(1, 3)
对于轴1(因为具有未屏蔽值的第一列是1,最后一列是3(第1列和第5列只包含掩码值))。在[我考虑过也许把numpy.ma.flatnotmasked_edges
和numpy.apply_along_axis
结合起来,但没有任何成功…]
你可以做到:
或者
^{pr2}$这里有一个based on ^{} -
相关问题 更多 >
编程相关推荐