Use numpy argmax to find the first occurrence of value greater than 5 in the following array:
arr = range(2, 20)
Use numpy argmax to find the first occurrence of value greater than 5 in the following array:
arr = range(2, 20)
import numpy as np
arr = np.array(range(2, 20))
idx = np.argmax(np.concatenate((arr[arr <= 5], [arr[arr > 5][0]])))
or
import numpy as np
arr = np.array(range(2, 20))
idx = np.argmax(arr[arr <= 5]) + 1