Also see How to find first element in sorted numpy array that is smaller than a given scalar
You can use np.searchsorted()
like this:
idx = np.searchsorted(arr, scalar, side='right') + 1
Full example:
import numpy as np # Example array arr = np.array([1, 2, 3, 4, 5]) # We'll search for this value scalar = 3.5 # Use numpy.searchsorted() to find the first element in the array that is larger than the scalar # We need to use + 1 since searchsorted() returns the first element that is smaller than the scalar idx = np.searchsorted(arr, scalar, side='right') + 1 # Print the resulting index print(idx)