python extract elements from array

Viewed 38820

I have an 8000-element 1D array.

I want to obtain the following two arrays:

  1. test contains the element with the index from [1995:1999], [3995:3999], [5999:5999], [7995:7999].

  2. train should contains everything else.

How should I do that?


idx = [1995,1996,1997,1998, 1999, 3995, 3996, 3997,3998, 3999, 5995, 5996, 5997, 5998, 5999, 7995, 7996, 7997, 7998, 7999]
test = [X[i] for i in idx]

train = [X[i] for i **not** in idx]
5 Answers
Related