[Numpy-discussion] Reversing an array in-place

Justin Peel jpscipy@gmail....
Mon Dec 20 14:25:05 CST 2010


I noticed that there is currently no way to reverse a numpy array
in-place. The current way to reverse a numpy array is using slicing,
ala arr[::-1]. This is okay for small matrices, but for really large
ones, this can be prohibitive. Not only that, but an in-place reverse
is much faster than slicing. It seems like a reverse method could be
added to arrays that would reverse the array along a given axis fairly
easily. Is there any opposition to this?

Also, there is consideration for simply marking a given axis as being
reverse similar to how transposes are taken. However, I see this as a
problem for a method like reshape to deal with and therefore think
that it is better to just add a reverse method. What are your
opinions?

I'm quite willing to make such a method if it will be accepted.

Justin Peel


More information about the NumPy-Discussion mailing list