I think this could be simplified dramatically. You're spending a long time above vstacking, only to transpose here? I think a single np.array() call, maybe with a .T, would be sufficient. Ideally, I don't think you even need to do an array conversion. I don't understand why the output is not simply `ii[end] - ii[start]`?