# numpy.argmax () in Python

|

numpy.argmax (array, axis = None, out = None): returns the indices of the max element of the array on a specific axis.
Parameters:

`  array:  Input array to work on  axis:  [int, optional] Along a specified axis like 0 or 1  out:  [array optional] Provides a feature to insert output to the  out  array and it should be of appropriate shape and dtype `

Return:

` Array of indices into the array with same shape as array.shape with the dimension along axis removed. `

Code 1 :

 ` # Python program illustrating ` ` # argmax () work `   ` import ` ` numpy as geek `   ` # Working with 2D array ` ` a rray ` ` = ` ` geek.arange (` ` 12 ` `). reshape (` ` 3 ` `, ` ` 4 ` `) ` ` print ` ` (` ` "INPUT ARRAY:" ` `, array) `   ` # The axis is not specified, so it works on the whole array ` ` print ` ` (` ` "Max element:" ` `, geek.argmax (array)) `   ` # returns the max element indices ` ` # by indicators ` ` print ` ` (` ` "Indices of Max element: "< / code> , geek.argmax (array, axis = 0 )) `` print ( "Indices of Max element:" , geek.argmax (array, axis = 1 )) `

Output:

` INPUT ARRAY: [[0 1 2 3] [4 5 6 7] [8 9 10 11]] Max element : 11 Indices of Max element: [2 2 2 2] Indices of Max element: [3 3 3] `

Code 2:

 ` # Python program illustrating ` ` # argmax () work ` ` `  ` import ` ` numpy as geek `   ` # Working with 2D array ` ` array ` ` = ` ` geek.random.randint (` ` 16 ` `, size ` ` = ` ` (` ` 4 ` `, ` ` 4 ` `) ) ` ` print ` ` (` ` "INPUT ARRAY: "` `, array) ` ` `  ` # The axis is not specified, so it works for the entire array ` ` print ` ` (` ` "Max element:" ` `, geek.argmax (array)) `   ` # returns the indices of the max element ` ` # by metrics ` ` `  ` "" "` ` ` ` [[ 0 3 8 13] ` ` [12 11 2 11] ` ` [5 13 8 3] ` ` ` ` [12 15 3 4]] ` ` ^ ^ ^ ^ ` ` ` ` 12 15 8 13 - element ` ` 1 3 0 0 - indicators ` ` "" "` ` print ` ` (` `" Indices of Max element: "` `, geek. argmax (array, axis ` ` = ` ` 0 ` `)) `     ` "" "` ` ` ` ITEM INDEX ` ` -" [[0 3 8 13] 13 3 ` ` -" [12 11 2 11] 12 0 ` ` -" [5 13 8 3] 13 1 ` ` -" [12 15 3 4]] 15 1 `   ` "" "` ` print ` ` (` ` "Indices of Max element:" ` `, geek.argmax (array, axis ` ` = ` ` 1 ` `)) `

Output:

` INPUT ARRAY: [[0 3 8 13] [12 11 2 11] [5 13 8 3] [12 15 3 4]] Max element: 15 Indices of Max element: [1 3 0 0] Indices of Max element: [3 0 1 1] `

Code 3:

 ` # Python program illustrating ` ` # argmax () work `   ` import ` ` numpy as geek  ``   # Working with 2D array array =   geek.arange ( 10 ). Reshape ( 2 , 5 ) print ( "array:" , array)   array [ 0 ] [ 1 ] = 6 print ( " array : " , array)    # Returns the max element print ( "array:" , geek.argmax (array))   # The first occurrence of the max element given print ( "MAX ELEMENT INDICES:" , geek.argmax (array, axis = 0 )) `

Output:

` array: [[0 1 2 3 4] [5 6 7 8 9]] array: [[0 6 2 3 4] [5 6 7 8 9]] array: 9 MAX ELEMENT INDICES: [1 0 1 1 1] `

Notes:
These codes will not work for online IDs. Please run them on your systems to see how they work

## Shop Learn programming in R: courses

\$ Best Python online courses for 2022

\$ Best laptop for Fortnite

\$ Best laptop for Excel

\$ Best laptop for Solidworks

\$ Best laptop for Roblox

\$ Best computer for crypto mining

\$ Best laptop for Sims 4

\$

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

NUMPYNUMPY

How to convert Nonetype to int or string?

NUMPYNUMPY

How to specify multiple return types using type-hints

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

## Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method