Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Numpy: abs value on a Numpy array

  • abs
  • absolute
import numpy as np

a = np.array([[-1, 2, -3], [-4, 5, -7]])
print(a)
print(a.dtype)
print()

abs_a = np.absolute(a)
print(abs_a)
print(abs_a.dtype)
print()
print(a)
[[-1  2 -3]
 [-4  5 -7]]
int64

[[1 2 3]
 [4 5 7]]
int64

[[-1  2 -3]
 [-4  5 -7]]