的Python:获得在numpy的阵列的最大项目的位置 [英] Python: get the position of the biggest item in a numpy array

查看:204
本文介绍了的Python:获得在numpy的阵列的最大项目的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能得到一个多维数组numpy的最大项目的位置?

How can I get get the position of the biggest item in a multi-dimensional numpy array?

推荐答案

的<一个href=\"http://www.scipy.org/Numpy_Example_List#head-e2829234dedbedccc333d32ee2738c28777f2e94\"><$c$c>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)

这篇关于的Python:获得在numpy的阵列的最大项目的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆