I have a numpy array of indeterminate size and I need to compare some indices being used to extract data. For example if start_index > end_index
I want an error to be thrown. However, sometimes the indices might be negative, most notably we might have end_index = -1
to represent the final element in the array. If I just straight up compared the indices and end_index
was negative an error could be thrown incorrectly.
My current solution is to check if start_index % array_length > end_index % array_length
.
This does work, but I'm now having to think about everything using modular arithmetic. Does anyone know of a more efficient solution, perhaps a tool from numpy itself?