Let's say we have two sorted numpy arrays, `a`

and `b`

.

```
a = np.array([ 0, 1, 2, 10])
b = np.array([ 7, 13])
```

For each element array `a`

, I want to subtract the first larger element in `b`

to get something like this:

```
>>> f(a, b)
array([-7, -6, -5, -3])
```

I can do this with an inefficient for loop, but is there a more numpythonic way to do it?

You could use

`searchsorted`

for this. It will require that`b`

is sorted and that`a`

doesn't have values greater than the largest in`b`

.