python - Most efficient way to reverse a numpy array -


believe or not, after profiling current code, repetitive operation of numpy array reversion ate giant chunk of running time. have right common view-based method:

reversed_arr = arr[::-1] 

is there other way more efficiently, or illusion obsession unrealistic numpy performance?

when create reversed_arr creating view original array. can change original array, , view update reflect changes.

are re-creating view more need to? should able this:

arr = np.array(some_sequence) reversed_arr = arr[::-1]  do_something(arr) look_at(reversed_arr) do_something_else(arr) look_at(reversed_arr) 

i'm not numpy expert, seems fastest way things in numpy. if doing, don't think can improve on it.

p.s. great discussion of numpy views here:

view onto numpy array?


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -