2

Suppose there is an array like the below:

a = np.array([[1,2],
              [2,3],
              [2,3],
              [2,3],
              [4,5],
              [3,4],
              [2,3]])

How would I return multiple rows, this is what I would like to achieve (I know the syntax is wrong, but this will give you an idea of what I want to achieve):

a[0:2 & 5:6,:]

I would not be able to pass individual rows because in my actual code I would need to include larger ranges, e.g. 20:60 & 90:160, etc.

1 Answer 1

3

This works:

>>> a[np.r_[:2, 5:6], :]
array([[1, 2],
       [2, 3],
       [3, 4]])

The np.r_:

Translates slice objects to concatenation along the first axis.

Sign up to request clarification or add additional context in comments.

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.