Python | Numpy ndarray .__ abs __ ()

Numpy ndarray .__ abs __ () can be used to find the absolute value of each element in the array. Assuming we have 1.34 values, ndarray .__ abs __ () will convert it to 1 .

Syntax: ndarray .__ abs __ (self)

Return: floor (self)

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

# import an 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 ndarray .____ () method

print (gfg .__ abs __ ())

Exit :

 [1 2 3 4 5 6] 

Example # 2:

# import important module in python

import numpy as np

 
# make an array with N umPy

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 the ndarray method .__ abs __ ()

print (gfg .__ abs __ ())

Exit:

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