获取最大项目在多维numpy数组中的位置 [英] Get the position of the biggest item in a multi-dimensional numpy array
本文介绍了获取最大项目在多维numpy数组中的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何获取多维numpy数组中最大项的位置?
How can I get get the position of the biggest item in a multi-dimensional numpy array?
推荐答案
argmax()
方法应该有帮助.
The argmax()
method should help.
更新
(阅读评论后)我相信argmax()
方法也适用于多维数组.链接的文档提供了以下示例:
(After reading comment) I believe the argmax()
method would work for multi dimensional arrays as well. The linked documentation gives an example of this:
>>> a = array([[10,50,30],[60,20,40]])
>>> maxindex = a.argmax()
>>> maxindex
3
更新2
(由于 KennyTM 的注释),您可以使用unravel_index(a.argmax(), a.shape)
将索引作为元组获取:
(Thanks to KennyTM's comment) You can use unravel_index(a.argmax(), a.shape)
to get the index as a tuple:
>>> from numpy import unravel_index
>>> unravel_index(a.argmax(), a.shape)
(1, 0)
这篇关于获取最大项目在多维numpy数组中的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文