Selecting vector elements
To select vector elements, you can use a vector containing logical values (expressions). The elements of the vector that will be
True
in the vector with boolean values will be selected.
Example
import numpy as np
V = np.array([1,-2,3,-4,5])
# select the first two elements of the vector
print(V[np.array((True, True, False, False, False))]) # [ 1 -2]
# select positive vector elements
print(V[V > 0]) # [1 3 5]
# select even vector elements
print(V[V % 2 == 0]) # [-2 -4]