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: Logical not on a Numpy array

  • logical_not
  • not
  • True
  • False
  • bool
import numpy as np

a = np.array([True, True, False])
print(a.dtype)
print(a)
print()

not_a = np.logical_not(a)
print(not_a.dtype)
print(not_a)
print()

b = np.array([True, True, False, 0, 42])
print(b.dtype)
print(b)
print()

not_b = np.logical_not(b)
print(not_b.dtype)
print(not_b)
print()
bool
[ True  True False]

bool
[False False  True]

int64
[ 1  1  0  0 42]

bool
[False False  True  True False]