gpt4 book ai didi

python - 在 Python 的 NumPy 中确定最高值的索引

转载 作者:太空狗 更新时间:2023-10-29 17:58:20 24 4
gpt4 key购买 nike

我想生成一个数组,其中索引为每行的最高最大值。

a = np.array([ [1,2,3], [6,5,4], [0,1,0] ])
maxIndexArray = getMaxIndexOnEachRow(a)
print maxIndexArray

[[2], [0], [1]]

有一个 np.argmax 函数,但它似乎没有执行我想要的...

最佳答案

argmax() 函数你想做的事:

print a.argmax(axis=1)
array([2, 0, 1])

关于python - 在 Python 的 NumPy 中确定最高值的索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4150542/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com