问题
方法
import numpy as np
# (1)
a = np.random.randint(0, 2, 10)
print(a) # [1 1 1 0 0 1 1 1 0 0]
print(np.invert(a)) # [-2 -2 -2 -1 -1 -2 -2 -2 -1 -1]
b = a.astype(np.bool)
b = ~b
print(b) # [ True False False False False False False True True True]
c = b.astype(np.int32)
print(c) # [1 0 0 0 0 0 0 1 1 1]
# (2) 如果针对某一位取反
d = a[5].astype(np.bool)
d = ~d
a[5] = d.astype(np.int32)
print(a[5])