For an array of real numbers, absolute() simply removes the sign from each element. For an array of complex numbers, it instead computes each element's magnitude, the distance from the origin in the complex plane, the same generalization the built-in abs() function applies to a single complex number. np.abs is just a shorter alias for the exact same function; both names are equally valid and commonly used.
1Understanding np.absolute()
For an array of real numbers, absolute() simply removes the sign from each element. For an array of complex numbers, it instead computes each element's magnitude, the distance from the origin in the complex plane, the same generalization the built-in abs() function applies to a single complex number. np.abs is just a shorter alias for the exact same function; both names are equally valid and commonly used.
np.abs() and np.absolute() are the exact same function under two names — use whichever reads better in context, there's no functional difference.
import numpy as np
arr = np.array([-3, -1, 0, 2, 5])
print(np.absolute(arr))2Practical Example
Here is a real-world application of np.absolute() showing how it is used in production NumPy code.
import numpy as np
complex_arr = np.array([3 + 4j, 1 - 1j])
print(np.abs(complex_arr))3Best Practices
Follow these guidelines when working with np.absolute():
1. Use np.abs(a - b) to compute element-wise distance/difference between two arrays instead of a manual sign check
2. Use absolute() on complex arrays when you need magnitude, understanding the result will be a real-valued array, not complex
3. Combine np.abs() with a tolerance comparison, or np.isclose(), instead of == when checking whether array values are close to a target
Tip: np.abs() and np.absolute() are the exact same function under two names — use whichever reads better in context, there's no functional difference.
import numpy as np
arr = np.array([-3, -1, 0, 2, 5])
print(np.absolute(arr))