首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >numpy数组的最大打印索引

numpy数组的最大打印索引
EN

Stack Overflow用户
提问于 2019-06-12 00:55:33
回答 2查看 1.9K关注 0票数 0

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

代码语言:javascript
复制
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在最终数组中找到最大值。

EN

回答 2

Stack Overflow用户

发布于 2019-06-12 01:00:01

使用numpy.argmax查找最大值的索引。

票数 1
EN

Stack Overflow用户

发布于 2019-06-12 01:26:09

代码语言:javascript
复制
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]}")
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56553347

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档