Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding argmax

Tags:

python

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.

like image 542
user71346 Avatar asked Mar 30 '16 05:03

user71346


People also ask

What does argmax function do?

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.

What's the difference between Max and argmax?

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.

What is argmax of a matrix?

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.

How do you read ARG Max?

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."


1 Answers

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 
like image 97
roadrunner66 Avatar answered Sep 19 '22 14:09

roadrunner66