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.