numpy.argmax() in Python

The Python numpy.argmax() function returns the indices of maximum elements along the specific axis inside the array.

Basic Syntax

Following is the basic syntax for numpy.argmax() function in Python:

numpy.argmax(arr, axis=None, out=None)

And the parameters are:

ParameterDescription
arrThe input array
axis[int, OPTIONAL] Along the axis like 1 or 0.
out[array, OPTIONAL] If provided then it will insert output to the out array with appropriate shape.

 

Return Value

This function returns array of indices into the array.

Example’s

Following are the examples for numpy.argmax() function:

Example 1

The output for the above program is as given below:

The input array:
[[ 0, 1, 2, 3, 4],
[ 5, 6, 7, 8, 9],
[10, 11, 12, 13, 14]]
The max element: 14
The indices of max element: [2, 2, 2, 2, 2]
The indices of max element: [4, 4, 4]

Example 2

The output for the above program is as given below:

The input array:
[[ 0, 1, 17, 3, 4],
[ 5, 6, 7, 8, 9],
[10, 11, 12, 13, 14],
[15, 16, 17, 18, 19]]
The max element: ‘, 19)
The indices of max element: ‘, array([3, 3, 0, 3, 3]
The indices of max element: ‘, array([2, 4, 4, 4]

LEAVE A REPLY

Please enter your comment!
Please enter your name here