Python Numpy argmax()

Python Numpy argmax()

NumPy generally stands for Numerical Python and it is a general purpose array processing always provides a high performance multidimensional array object. Numpy is usually for creating an array of n dimensions.

Method Name :numpy.argmax()
Description :This function returns indices of the max element of the array in a particular axis.
Searching is an operation or a technique that helps find the place of a given element or value in the list. Anytype of search is said to be successful or unsuccessful depending upon whether the element that is being searched is found or not. In Numpy, we can perform various searching operations using the various functions that are provided in the library like argmax, argmin, nanaargmax etc.

In this article, I will tell you about the parameter and its description
Parameter Name: numpy.nanargmin()
Description : Return the indices of the minimum values in the specified axis ignoring NaNs

Parameter Name:numpy.argwhere()
Description : Find the indices of array elements that are non-zero, grouped by element.

Parameter Name: numpy.nonzero()
Description : Return the indices of the elements that are non-zero.

Parameter Name: numpy.flatnonzero()
Description : Return indices that are non-zero in the flattened version of a.

Parameter Name: numpy.where()
Description : Return elements chosen from x or y depending on condition.

Parameter Name: numpy.searchsorted()
Description : Find indices where elements should be inserted to maintain order.

Parameter Name: numpy.extract()
Description : Return the elements of an array that satisfy some condition.

The first step would be to give syntax

Example :
Code :
# working of argmax() import numpy as np # Working on 2D array array =np.arange(16).reshape(4, 4) print("INPUT ARRAY : ", array) # No axis mentioned, so works on entire array print("Max element : ", np.argmax(array)) # returning Indices of the max element # as per the indices print(("Indices of Max element : " , np.argmax(array, axis=0))) print(("Indices of Max element : " , np.argmax(array, axis=1)))

Output :
Example :
Code :
# working of nanargmax() import numpy as np # Working on 1D array array = [np.nan, 5,6,7,8] print("INPUT ARRAY 1 : ", array) array2 = np.array([[np.nan, 8], [4,4]]) # returning Indices of the max element # as per the indices ingnoring NaN print(("Indices of max in array1 : " , np.nanargmax(array))) # Working on 2D array print("INPUT ARRAY 2 : ", array2) print(("Indices of max in array2 : " , np.nanargmax(array2))) print(("Indices at axis 1 of array2 : " , np.nanargmax(array2, axis = 1)))

Output :