Suppose I have a list:
import numpy as np a = [2, 4, 6, 8, ..., 1000]
I want to get from the 1st to the 100th, from the 201st to the 300th, from 401 to 500 elements and turn them into a new array.
For this purpose I tried the following codes:
a_sub = a[0:100] + a[200:300] + a[400:500] b_sub = np.concatenate((b[0:100], b[200:300], b[400:500]))
But I want to do this with simple oneline indexing
Say:
a_sub = a[(0:100, 200:300, 400:500)] a_sub = a[[0:100, 200:300, 400:500]] b_sub = b[[0:100, 200:300, 400:500]] b_sub = b[[0:100, 200:300, 400:500]]
But above all are invalid, and I could not find such an oneliner indexing.
source share