In [1]:
import numpy as np
In [2]:
a_1d = np.arange(4)
print(a_1d)
In [3]:
print(a_1d[[True, False, True, False]])
In [4]:
print(a_1d[np.array([True, False, True, False])])
In [5]:
# print(a_1d[[True, False]])
# IndexError: boolean index did not match indexed array along dimension 0; dimension is 4 but corresponding boolean dimension is 2
In [6]:
a_2d = np.arange(12).reshape(3, 4)
print(a_2d)
In [7]:
print(a_2d[[True, False, True]])
In [8]:
print(a_2d[:, [True, False, True, False]])
In [9]:
print(a_2d[[True, False, True], [True, False, True, False]])
In [10]:
print(a_2d[np.ix_([True, False, True], [True, False, True, False])])
In [11]:
print(a_2d[:, [True, False, False, False]])
In [12]:
print(a_2d > 5)
In [13]:
print(type(a_2d > 5))
In [14]:
print(a_2d[a_2d > 5])
In [15]:
print((a_2d > 5) & (a_2d < 10))
In [16]:
print(a_2d[(a_2d > 5) & (a_2d < 10)])