-3

If I have an array in python:

a = np.array([20, 21, 19, 85, 25, 31, 21, 99, 3])

and I want to find the max value between indices 2 and 5 to return 85. How can I do this?

I know a.max() will output the value 99, but I am not sure how to specify the range.

sci-guy
  • 2,154
  • 4
  • 22
  • 44

2 Answers2

3

Just use slicing.

a = np.array([20, 21, 19, 85, 25, 31, 21, 99, 3])
a[2:5].max()

gives 85 as max value.

error
  • 2,196
  • 3
  • 21
  • 24
1

Simply call a[2:5].max().

It will search in the sub array containing the elements you're interested in.