  # Numpy MaskedArray.argmax () Function | python

NumPy | Python Methods and Functions

`numpy.MaskedArray.argmax()` returns an array of indices of the maximum values ​​along the given axis. Masked values ​​are treated as if they had fill_value.

Syntax: ` numpy.MaskedArray.argmax (axis = None, fill_value = None, out = None) `

Parameters:
axis: [None, integer] If None, the index is into the flattened array, otherwise along the specified axis.
fill_value: [var, optional] Value used to fill in the masked values.
out: [ndarray , optional] A location into which the result is stored.
- & gt; If provided, it must have a shape that the inputs broadcast to.
- & gt; If not provided or None, a freshly-allocated array is returned.

Return: [index_array] A new integer_array is returned unless out is specified, in which case a reference to out is returned.

Code # 1:

 ` # Python program explaining ` ` # numpy.MaskedArray.argmax () method `   ` # import numy as geek ` ` # and numpy.ma module as ma ` ` import ` ` numpy as geek ` ` import ` ` numpy.ma as ma `   ` # create input array ` ` in_arr ` ` = ` ` geek.array ([` ` 1 ` `, ` ` 2 ` `, ` ` 3 ` `, ` ` - ` ` 1 ` `, ` ` 5 ` `]) ` ` print ` ` (` ` "Input array:" ` `, in_arr) `   ` # We are now creating a masked array. ` ` # making the third entry invalid. ` ` mask_arr ` ` = ` ` ma.masked_array (in_arr, mask ` ` = ` ` [` ` 0 ` `, ` ` 0 < / code> , 1 , 0 , 0 ]) `` print ( "Masked array:" , mask_arr)    # applying MaskedArray.argmax methods to mask array out_arr = mask_arr.argmax ( ) print ( "Index of max element in masked array: " , out_arr) `

Output :

` Input array: [1 2 3 -1 5] Masked array: [1 2 - -1 5] Index of max element in masked array: 4 `

Code No. 2:

 ` # Python program explaining ` ` # numpy.MaskedArray.argmax () method `   ` # import numy as a geek ` ` # and the numpy.ma module as ma ` ` import ` ` numpy as geek ` ` import ` ` numpy.ma as ma `   ` # create input array ` ` in_arr ` ` = ` ` geek.array ([` ` 10 ` `, ` ` 20 ` `, ` ` 30 ` `, ` ` - ` ` 10 ` `, ` ` 50 ` `]) ` ` print ` ` (` `" Input array: "` `, in_arr) ` ` `  ` # We now create a masked array ` ` # invalidating the first third post. ` ` mask_arr ` ` = ` ` ma.masked_array (in_arr, mask ` ` = ` ` [` ` 1 ` `, ` ` 0 ` `, ` ` 1 ` `, ` ` 0 ` `, ` ` 0 ` `]) ` ` print < / code> ( "Masked array:" , mask_arr) ``   # using MaskedArray.argmax methods to mask the array # and filling the masked space by 100 `` out_arr = mask_arr.argmax (fill_value = 100 ) print ( "Index of max element in masked array: " , out_arr) `

Output :

` Input array: [10 20 30 -10 50] Masked array: [- 20 - -10 50] Index of max element in masked array: 0 `