NumPy ndarray.__abs__() | Find Absolute Value of Elements in NumPy Array
Last Updated :
05 Feb, 2024
The ndarray.__abs__() method returns the absolute value of every element in the NumPy array.
It is automatically invoked when we use Python’s built-in method abs() on a NumPy array.
Example
Python3
import numpy as np
gfg = np.array([ 1.45 , 2.32 , 3.98 , 4.41 , 5.55 , 6.12 ])
print (gfg.__abs__())
|
Syntax
Syntax: ndarray.__abs__()
Return: Returns an array with absolute values.
How to find Absolute Values of the NumPy Array
To find absolute values of the elements of NumPy array we use ndarray.__abs__() method of the NumPy library in Python.
Let’s understand it better with an example:
Example:
Python3
import numpy as np
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 ]])
print (gfg.__abs__())
|
Output
[[ 1 2 3 4 5 6 ]
[ 6 5 4 3 2 1]]
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...