This should be a little faster:

```
mask = vol != 0
mins = np.zeros(mask.ndim)
maxs = mins.copy()
for i in mask.ndim:
    flat = mask.any(i)
    mins[i] = flat.argmax()
    maxs[i] = mask.shape[i] - flat[::-1].argmax()

return mins, maxs
```