Numpy Boolean Indexing Mask(Numpy 布尔索引掩码 )
Numpy: Boolean Indexing
import numpy as np
A = np.array([4, 7, 3, 4, 2, 8])
print(A == 4)
Every element of the Array A is tested, if it is equal to 4. The results of these tests are the Boolean elements of the result array.
Of course, it is also possible to check on "<", "<=", ">" and ">=".
print(A < 5)
It works also for higher dimensions:
B = np.array([[42,56,89,65],
[99,88,42,12],
[55,42,17,18]])
print(B>=42)
It is a convenient way to threshold images.
import numpy as np
A = np.array([
[12, 13, 14, 12, 16, 14, 11, 10, 9],
[11, 14, 12, 15, 15, 16, 10, 12, 11],
[10, 12, 12, 15, 14, 16, 10, 12, 12],
[ 9, 11, 16, 15, 14, 16, 15, 12, 10],
[12, 11, 16, 14, 10, 12, 16, 12, 13],
[10, 15, 16, 14, 14, 14, 16, 15, 12],
[13, 17, 14, 10, 14, 11, 14, 15, 10],
[10, 16, 12, 14, 11, 12, 14, 18, 11],
[10, 19, 12, 14, 11, 12, 14, 18, 10],
[14, 22, 17, 19, 16, 17, 18, 17, 13],
[10, 16, 12, 14, 11, 12, 14, 18, 11],
[10, 16, 12, 14, 11, 12, 14, 18, 11],
[10