I guess `digitize` and `searchsorted` are nearly identical. Apparently the former does a linear (not binary) search, but it seems faster at scale.

We're dealing with pretty small times here, but on my system `digitize` takes a third of the time compared to your method with 30 classes and 1e6 samples, and half the time for 1e7 samples. The methods are competitive at around 100 classes, 1e7 samples. When we get to 1e8 samples, the fact that `prob_array[np.floor(rs * map_length).astype(int)]` creates 2 intermediate arrays of that size becomes more expensive than the computation.