Believe it or not, after profiling my current code, the repetitive operation of numpy array reversion ate a giant chunk of the running time. What I have right now is the common view-based method:
reversed_arr = arr[::-1]
Is there any other way to do it more efficiently, or is it just an illusion from my obsession with unrealistic numpy performance?
gives a reversed view into the original array
arr. Any changes made to the original arrayarrwill also be immediately visible inreversed_arr. The underlying data buffers forarrandreversed_arrare shared, so creating this view is always instantaneous, and does not require any additional memory allocation or copying for the array contents.See also, this discussion on NumPy views: How do I create a view onto a NumPy array?
Possible solutions to performance problems regarding views
Are you re-creating the view more often than you need to? You should be able to do something like this:
I’m not a numpy expert, but this seems like it would be the fastest way to do things in numpy. If this is what you are already doing, I don’t think you can improve on it.