Python 使用max打印numpy数组的索引

Python 使用max打印numpy数组的索引,python,numpy,argmax,Python,Numpy,Argmax,我想打印具有最大值的数组的索引(由于索引从0开始,我需要在索引值中添加一个以获得1索引)。例如: rslt = np.amax(final_array) print("The maximum value is :", rslt) print("The optimal choice that has that value is :", rslt.index[]) 上下文:我正在用Python编写一些多标准决策分析代码。我导入numpy来处理备选方案、标准和权重的数组。我使用np.amax查找最

我想打印具有最大值的数组的索引(由于索引从0开始,我需要在索引值中添加一个以获得1索引)。例如:

rslt = np.amax(final_array)
print("The maximum value is :", rslt)
print("The optimal choice that has that value is :", rslt.index[])


上下文:我正在用Python编写一些多标准决策分析代码。我导入numpy来处理备选方案、标准和权重的数组。我使用np.amax查找最终数组中的最大值

用于查找最大值的索引。

您所说的“最佳选择”是什么意思?你能定义那个索引保证是唯一的吗?会有多个这样的索引吗?几乎重复:。。。
import numpy as np

#some list
f = [1,2,3,4,5,6,6,6,6,6]

#max value
print (f"the max value is : { np.amax(f)}")

#indices where max values are located
max_indices = np.argwhere( f == np.amax(f))

#adding 1 to get position
max_positions = [i+1 for i in max_indices.flatten().tolist()]

print(f"Max values are located at : {max_positions}")

#first max value
print(f"First max value occurs at : {max_positions[0]}")