I can use an array or a list to index into numpy.array
, e.g.:
a = np.array([1, 2, 3, 4])
print(a[[1, 3]])
will produce
[2 4]
Is there an equivalent construct to index into a standard Python list or array?
Just to be more specific: indexing has to be with an array and indexing pattern is random, i.e. not possible with slicing. Here is a better example:
a = np.array([1, 2, 3, 4])
i = [3, 0, 1]
print(a[i])
.....
[4 1 2]