我想特别关注以下question:
如何在合适的a
索引中获取a[...]
的argmax
>>> a = (np.random.random((10, 10))*10).astype(int)
>>> a
array([[4, 1, 7, 4, 3, 3, 8, 9, 3, 0],
[7, 7, 8, 9, 9, 6, 1, 4, 2, 0],
[6, 9, 4, 9, 2, 7, 9, 0, 8, 6],
[2, 4, 7, 8, 0, 6, 0, 7, 1, 8],
[7, 9, 7, 0, 1, 2, 3, 7, 9, 6],
[7, 1, 1, 0, 5, 1, 8, 8, 5, 5],
[5, 4, 3, 0, 0, 4, 4, 5, 5, 4],
[9, 5, 0, 5, 8, 1, 6, 4, 8, 5],
[5, 8, 0, 8, 2, 6, 4, 9, 5, 1],
[2, 5, 0, 1, 4, 0, 0, 9, 6, 4]])
>>> np.unravel_index(a.argmax(), a.shape)
(0, 7)
>>> np.unravel_index(a[a>5].argmax(), a.shape)
(0, 2)
>>> np.unravel_index(a[a>5].argmax(), a[a>5].shape)
(2,)
2条答案
按热度按时间mf98qq941#
你可以考虑使用masked API:
结果:
xeufq47z2#
对于一个面具,什么是:
或