Suppose that I have a list:
import numpy as np
a = [2, 4, 6, 8, ..., 1000] # total 500 elements
b = np.array(a) # numpy version
I want to get 1st to 100th, 201st to 300th, 401st to 500th elements and make them into a new array.
To this end, I've 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 it with a 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 the above are all invalid and I couldn't find such a oneliner indexing.
a_sub = b[range(0,100)+range(200,300)+range(400,500)]a_sub = a[(0:100, 200:300, 400:500)]