3

I have a numpy array whose shape is (72, 671). Typically I select everything across the first dimension like this:

new_var = old_var[0:72]

However, for one file, I need to skip #18 across the first dimension. In other words, I want to select 0:17 and then 19:72 (or however you would write that correctly based on what is/isn't included). I have tried:

new_var=old_var[0:18,19:72]

but this only selects 0:18 in the first dimension and then 19:72 in the second. at least this is what I think it's doing, since the length of the resulting variable is 18. I can't find how to correct the syntax, so any help would be appreciated.

2 Answers 2

3

I think you can use np.r_

old_var = np.random.random((72,671))
new_var = old_var[np.r_[0:18,19:72]]
new_var.shape

Output:

(71, 671)
Sign up to request clarification or add additional context in comments.

Comments

2

You can use fancy indexing:

a[list(range(18)) + list(range(19, 72))]

Or np.vstack:

np.vstack((a[:18], a[19:]))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.