Skip to main content
added 146 characters in body; added 2 characters in body
Source Link
François
  • 8.2k
  • 2
  • 23
  • 18

Without using masked arrays, you could remove the indices greater or equal to 5 like this:

print input[indices[indices<5]]

Edit: note that if you also wanted to discard negative indices, you could write:

print input[indices[(0 <= indices) & (indices < 5)]]

Without using masked arrays, you could remove the indices greater or equal to 5 like this:

print input[indices[indices<5]]

Without using masked arrays, you could remove the indices greater or equal to 5 like this:

print input[indices[indices<5]]

Edit: note that if you also wanted to discard negative indices, you could write:

print input[indices[(0 <= indices) & (indices < 5)]]
Source Link
François
  • 8.2k
  • 2
  • 23
  • 18

Without using masked arrays, you could remove the indices greater or equal to 5 like this:

print input[indices[indices<5]]