[英]The use of numpy.argmax
I'm here to inquire about the use of numpy.argmax 我在这里询问有关numpy.argmax的使用
For instance, consider this array: 例如,考虑以下数组:
import numpy as np
a = np.arange(6).reshape(2,3)
b = np.argmax(a, axis = 0)
c = np.argmax(a, axis = 1)
print(a)
print(b)
print(c)
Here's the output: 这是输出:
[[0 1 2]
[3 4 5]]
5
[1 1 1]
[2 2]
I'm confused about the use of the parameter axis for numpy.argmax. 我对numpy.argmax的参数轴的使用感到困惑。 What does it do?
它有什么作用? Why does it return [1 1 1] if axis = 0 and [2 2] if the value of axis = 1?
如果axis = 0,为什么返回[1 1 1],如果axis = 1,为什么返回[2 2]?
numpy.argmax()
returns the position of the largest element in an array, optionally by row or column (the axis
argument). numpy.argmax()
返回数组中最大元素的位置,可以选择按行还是按列( axis
参数)返回。 So in the first case, [1 1 1]
, you get the position of the largest element column-wise. 因此,在第一种情况下
[1 1 1]
,您将获得列最大元素的位置。 Since the elements in row 1 are all larger that the elements in row 0, you get your array of three ones. 由于第1行中的元素都比第0行中的元素大,因此可以得到三个数组。 Analogously for
axis=1
, where you get the column of the largest element in each row. 类似于
axis=1
,您将在其中获得每一行中最大元素的列。
argmax returns to you the index of the max value along the axis you specified. argmax将沿指定轴返回最大值的索引。
The exact comparisons it did to get there: 它到达那里的确切比较:
3 > 0, 4 > 1, 5 > 2 : [1 1 1]
3> 0,4> 1,5> 2:
[1 1 1]
2 is the largest of set [0 1 2]
5 is the largest of set [3 4 5]
: 2是集合
[0 1 2]
中的最大值。5是集合[3 4 5]
的最大值:
[2 2]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.