What I want to do is zero the rows starting an index that change for each row. Example manual implementation would be
a[:2, 1:] = 0.
a[2:, 2:] = 0.
Is there a way to do it without having to do a loop? What would be given for example is a list of the lengths to keep for each row for example, in this case [1, 1, 2, 2], then the question is how to turn that into a mask.
I think if you are dealing with indices having a variable shape for each dimension, creating a mask should work. The mask creation itself might also involve a loop, which might be cheaper than the indexing loop.
Hm, in the end I want to sum over a certain axis. Is there no way to combine the mask plus summing in such a way so as to avoid doing operations on the just zeroed elements?