我见过这个问题 https://stackoverflow.com/questions/432112/is-there-a-numpy-function-to-return-the-first-index-of-something-in-an-array,但想要减少创建的数组mask = array == value
mask = array([[[ True, True, True],
[False, True, True]],
[[False, True, True],
[False, True, True]],
[[False, False, True],
[False, True, True]]])
这导致
where(mask) = (array([0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2]),
array([0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1]),
array([0, 1, 2, 1, 2, 1, 2, 1, 2, 2, 1, 2]))
我想将它减少到第一次出现的数组True
array([[0, 1],
[1, 1],
[2, 1]])
但无法从输出中找出如何解决这个问题numpy.where
。谁能帮我吗?