Python | Numpy MaskedArray .__ abs__

Arrays | NumPy | Python Methods and Functions

numpy.ma.MaskedArray class is a subclass of ndarray for manipulating numeric arrays with missing data. With the Numpy operator MaskedArray .__ abs__ we can find the absolute value of each element in the array. Suppose we have values ​​31,74, using MaskedArray .__ abs __ () it will be converted to 31.

Syntax: numpy.MaskedArray .__ abs__

Return: floor (self)

Example # 1:
In this example, we we see that after applying MaskedArray .__ abs __ () we get a simple array that can contain the absolute values ​​of all elements of the array.

# import important module into python

import numpy as np 

 
# make an array with NumPy

gfg = np.array ([ 1.45 , 2. 32 , 3.98 , 4.41 , 5.55 , 6.12 ]) 

 
# applying the MaskedArray method .____ ()

print (np.ma. MaskedArray .__ abs __ (gfg)) 

Output:

 [1 2 3 4 5 6] 

Example # 2:

# import important module in python

import numpy as np 

 
# make an array with NumPy

gfg = np.array ([[ 1.22 , 2.25 , - 3.21 , 4.45 , 5.56 , 6 ], 

[ - 6.65 , 5.55 , 4.32 , 3.33 , 2.12 , - 1.05 ]]) 

  
# applying MaskedArray .__ abs __ () method

print (np.ma.MaskedArray .__ abs __ (gfg)) 

Exit:

 [[1 2 3 4 5 6] [6 5 4 3 2 1]] 




Get Solution for free from DataCamp guru