[python] behavior of argmax

argmax outputs the element number of the one with the largest dimension specified by axis.

tmp.py


import numpy as np

array = [[2,3,4],
         [5,6,4],
         [3,2,1],
         [2,1,3]]
array = np.array(array)

print(np.argmax(array, axis=0)) # [1 1 0]
print(np.argmax(array, axis=1)) # [2 1 0 2]

Output explanation When axis = 0

In print (np.argmax (array, axis = 0)), [2,5,3,2] [3,6,2,1] [4,4,1,3] are targeted. Therefore, "5", "6", "4" are picked up. Each element number is [1 1 0].

Explanation of output When axis = 1

In print (np.argmax (array, axis = 1)), [2,3,4], [5,6,4], [3,2,1], [2,1,3] are targeted. Therefore, "4", "6", "3", "3" are picked up. Each element number is [2 1 0 2].

By the way,

If axis is not specified, it will be 4. I haven't investigated this for some reason.

tmp.py


print(np.argmax(array) #=> 4

Recommended Posts

[python] behavior of argmax
Behavior of python3 by Sakura's server
Introduction of Python
Behavior of multiprocessing.pool.Pool.map
Basics of Python ①
Basics of python ①
Copy of python
Introduction of Python
Check the behavior of destructor in Python
[Python] Operation of enumerate
List of python modules
Unification of Python environment
Copy of python preferences
Basics of Python scraping basics
Python default argument behavior
Usage of Python locals ()
the zen of Python
Installation of Python 3.3 rc1
blender, python, sphere behavior
# 4 [python] Basics of functions
About the behavior of Model.get_or_create () of peewee in Python
Basic knowledge of Python
Sober trivia of python3
Summary of Python arguments
Basics of python: Output
Installation of matplotlib (Python 3.3.2)
Application of Python 3 vars
Various processing of Python
Indent behavior of json.dumps is different between python2 and python3
[Python] Correct usage of map
Towards the retirement of Python2
Summary of python file operations
Summary of Python3 list operations
Python --Quick start of logging
Recommendation of binpacking library of python
[python] Value of function object (?)
Automatic update of Python module
Python --Check type of values
[Python] Etymology of python function names
behavior of matplotlib: histogram normed
About the ease of Python
Static analysis of Python programs
About various encodings of Python 3
Equivalence of objects in Python
Introduction of activities applying Python
python> Handling of 2D arrays
Install multiple versions of Python
Version upgrade of python Anaconda
Handling of python on mac
python: Basics of using scikit-learn ①
2.x, 3.x character code of python
Comparison of 4 Python web frameworks
Simple FPS measurement of python
Check OpenSSL version of python 2.6
Python implementation of particle filters
Post processing of python (NG)
[Python] Copy of multidimensional list
Faster loading of Python images
Sample usage of Python pickle
Behavior of pandas rolling () method
Basic usage of Python f-string