Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I am a beginner in Deep Learning and while performing a practical assignment, came across the Keras documentation on keras.backend .

I went through the explanation a number of times. however, i cannot exactly understand the difference between max and argmax function.

I will explain this using max and argmax from the numpy package, but the two functions are identical to the ones in the Keras backend:

import numpy as np
vector = np.array([1, 2, 3, 2, 1])

Now, np.max(vector) returns the number 3, as this is the maximal value in the vector. np.argmax(vector) however returns 2, as this is the index of the maximal value in the vector.

The argmax function is often used to post-process the output of a softmax layer. Say the output layer of your classifier (which classifies some image into one of four classes) is

output = Dense(4, activation='softmax')(...)

and the output of predict(some_random_image) is [0.02, 0.90, 0.06, 0.02]. Then, argmax([0.02, 0.90, 0.06, 0.02]) immediately gives you the class (1).

ohh.. so max will return the actual value and argmax will just return the index for that value. Thanks a lot for your answer @IonicSolutions – cadip92 Oct 18, 2018 at 17:05 Yes, exactly. I also added an example how the argmax function is regularly used in classification problems. (If the answer helped you, please consider upvoting and accepting it. Thanks!) – IonicSolutions Oct 18, 2018 at 17:07 Why isn't argmax named 'max_index'? The distinction between the two is simple enough to express using proper naming conventions. – typhon04 Feb 27, 2020 at 16:45

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.