我是新手,所以请原谅我的菜鸟问题。
import numpy as np
x = np.random.randint(120, size=(10, 4))
x
输出:
array([[ 69, 60, 86, 33],
[ 11, 68, 104, 46],
[ 62, 106, 15, 64],
[ 96, 47, 3, 36],
[ 82, 12, 110, 5],
[ 12, 92, 44, 96],
[ 67, 4, 71, 30],
[ 19, 70, 91, 18],
[ 70, 34, 115, 29],
[108, 88, 22, 57]])
a = np.argmax(x, axis=1)
print("Index of maximum value of each row of the array is: ", a)
输出:
Index of maximum value of each row of the array is: [2 2 1 0 2 3 2 2 2 0]
现在我想列出每行中最大数量的 values 。应该是
[86 104 106 96 110 96 71 91 115 108]
回答1
您可以使用:
np.max(x, axis=1)
这输出:
[ 86 104 106 96 110 96 71 91 115 108]