Let say I have the matrix
import numpy as np A = np.matrix([[1,2,3,33],[4,5,6,66],[7,8,9,99]])
I am trying to understand the function argmax, as far as I know it returns the largest value
If I tried it on Python:
np.argmax(A[1:,2])
Should I get the largest element in the second row till the end of the row (which is the third row) and along the third column? So it should be the array [6 9], and arg max should return 9? But why when I run it on Python, it returns the value 1?
And if I want to return the largest element from row 2 onwards in column 3 (which is 9), how should I modify the code?
I have checked the Python documentation but still a bit unclear. Thanks for the help and explanation.
argmax() function returns indices of the max element of the array in a particular axis. Return : Array of indices into the array with same shape as array.
The max function gives the largest possible value of f(x) for any x in the domain, which is the function value achieved by any element of the argmax. Unlike the argmax, the max function is unique since all elements of the argmax achieve the same value. However, the max may not exist because the argmax may be empty.
method matrix. argmax(axis=None, out=None)[source] Indexes of the maximum values along an axis. Return the indexes of the first occurrences of the maximum values along the specified axis.
That "big caret" is "and". This says "Argmax(f) is the set of all values of x such that f(x) is larger than equal to f(y) for all y in the set S." Equivalently, "Argmax(f) is the set of all x that give the maximum value of f."
No argmax
returns the position of the largest value. max
returns the largest value.
import numpy as np A = np.matrix([[1,2,3,33],[4,5,6,66],[7,8,9,99]]) np.argmax(A) # 11, which is the position of 99 np.argmax(A[:,:]) # 11, which is the position of 99 np.argmax(A[:1]) # 3, which is the position of 33 np.argmax(A[:,2]) # 2, which is the position of 9 np.argmax(A[1:,2]) # 1, which is the position of 9
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With