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.

Naz
  • 2,012
  • 1
  • 21
  • 45

1 Answers1

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.

unutbu
  • 842,883
  • 184
  • 1,785
  • 1,677
Mike Müller
  • 82,630
  • 20
  • 166
  • 161