# How to find first element in sorted numpy array that is smaller than a given scalar

*Also see How to find first element in sorted numpy array that is larger than a given scalar*

You can use `np.searchsorted()`

like this:

```
idx = np.searchsorted(arr, scalar, side='left')
```

### 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 smaller than the scalar
idx = np.searchsorted(arr, scalar, side='left')
# Print the resulting index
print(idx)
```