[英]Python Max/Position, array [[]]
I have an array.我有一个数组。 I got the max value with
max = np.max(List)
.我得到了 max
max = np.max(List)
。 Now I need the position of the max value.现在我需要最大值的位置。 I used this code:
我使用了这个代码:
x = np.where(a == a.max())
but it gives me that:但它给了我:
(array([0], dtype=int64), array([9], dtype=int64))
It contains the position but I don't know how to get it out of there.它包含该职位,但我不知道如何将其删除。 It would also be nice to know how to get the array below out of one of the two
[]
.知道如何从两个
[]
之一中获取下面的数组也很好。
array([[10.39219 , 12.018309, 13.810752, 10.646565, 13.779528, 13.29911 ,
13.650783, 12.464462, 13.427543, 14.388401]], dtype=float32)
Methods:方法:
np.argmax
:np.argmax
:List = np.array([10.39219 , 12.018309, 13.810752, 10.646565, 13.779528, 13.29911 , 13.650783, 12.464462, 13.427543, 14.388401])
_max = np.argmax(List)
_max
>>> 9
max
and index
methods:max
和index
方法:List = np.array([10.39219 , 12.018309, 13.810752, 10.646565, 13.779528, 13.29911 , 13.650783, 12.464462, 13.427543, 14.388401])
_max = List.tolist().index(max(List))
_max
>>> 9
use np.argmax()
to get the index使用
np.argmax()
获取索引
arr = array([[10.39219 , 12.018309, 13.810752, 10.646565, 13.779528, 13.29911 , 13.650783, 12.464462, 13.427543, 14.388401]], dtype=float32)
np.argmax(arr)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.