seems to work fine Your code is so slow because you're using Python's own sum() instead of numpy.sum() or numpy.array.sum(); Python's sum() has to convert all the raw values to Python objects before doing the calculations, which is really slow. Just by changing sum(...) to np.sum(...) or (...).sum(), the runtime drops to under 20 seconds.
I hope this helps . It's basically what the error says - In the second example, you are providing 2 groups (probs = c(.3,.7)), which is fewer than the amount of labels you provide (c("L","M","B")) Notice that in your first code snippet, seq(0,1 , by= 0.5) You generate 3 distinct values (0.0, 0.5, 1.0)
How to compute moving (or rolling, if you will) percentile/quantile for a 1d array in numpy?