Proposal for a new function: np.moveaxis
I've put up a pull request implementing a new function, np.moveaxis, as an alternative to np.transpose and np.rollaxis: https://github.com/numpy/numpy/pull/6630 This functionality has been discussed (even the exact function name) several times over the years, but it never made it into a pull request. The most pressing issue is that the behavior of np.rollaxis is not intuitive to most users: https://mail.scipy.org/pipermail/numpydiscussion/2010September/052882.html https://github.com/numpy/numpy/issues/2039 http://stackoverflow.com/questions/29891583/reasonwhynumpyrollaxisisso... In this pull request, I also allow the source and destination axes to be sequences as well as scalars. This does not add much complexity to the code, solves some additional use cases and makes np.moveaxis a proper generalization of the other axes manipulation routines (see the pull requests for details). Best of all, it already works on ndarray duck types (like masked array and dask.array), because they have already implemented transpose. I think np.moveaxis would be a useful addition to NumPy  I've found myself writing helper functions with a subset of its functionality several times over the past few years. What do you think? Cheers, Stephan
I'm just a lowly user, but I'm a fan of this. +1! On Thu, Nov 5, 2015 at 6:42 PM, Stephan Hoyer <shoyer@gmail.com> wrote:
I've put up a pull request implementing a new function, np.moveaxis, as an alternative to np.transpose and np.rollaxis: https://github.com/numpy/numpy/pull/6630 This functionality has been discussed (even the exact function name) several times over the years, but it never made it into a pull request. The most pressing issue is that the behavior of np.rollaxis is not intuitive to most users: https://mail.scipy.org/pipermail/numpydiscussion/2010September/052882.html https://github.com/numpy/numpy/issues/2039 http://stackoverflow.com/questions/29891583/reasonwhynumpyrollaxisisso... In this pull request, I also allow the source and destination axes to be sequences as well as scalars. This does not add much complexity to the code, solves some additional use cases and makes np.moveaxis a proper generalization of the other axes manipulation routines (see the pull requests for details). Best of all, it already works on ndarray duck types (like masked array and dask.array), because they have already implemented transpose. I think np.moveaxis would be a useful addition to NumPy  I've found myself writing helper functions with a subset of its functionality several times over the past few years. What do you think? Cheers, Stephan
Also a +1 from me. I've had to (re)learn how exactly np.transpose works more times then I care to admit.  Jonathan Helmus On 11/05/2015 02:26 AM, Juan NunezIglesias wrote:
I'm just a lowly user, but I'm a fan of this. +1!
On Thu, Nov 5, 2015 at 6:42 PM, Stephan Hoyer <shoyer@gmail.com <mailto:shoyer@gmail.com>> wrote:
I've put up a pull request implementing a new function, np.moveaxis, as an alternative to np.transpose and np.rollaxis: https://github.com/numpy/numpy/pull/6630
This functionality has been discussed (even the exact function name) several times over the years, but it never made it into a pull request. The most pressing issue is that the behavior of np.rollaxis is not intuitive to most users: https://mail.scipy.org/pipermail/numpydiscussion/2010September/052882.html https://github.com/numpy/numpy/issues/2039 http://stackoverflow.com/questions/29891583/reasonwhynumpyrollaxisisso...
In this pull request, I also allow the source and destination axes to be sequences as well as scalars. This does not add much complexity to the code, solves some additional use cases and makes np.moveaxis a proper generalization of the other axes manipulation routines (see the pull requests for details).
Best of all, it already works on ndarray duck types (like masked array and dask.array), because they have already implemented transpose.
I think np.moveaxis would be a useful addition to NumPy  I've found myself writing helper functions with a subset of its functionality several times over the past few years. What do you think?
Cheers, Stephan
_______________________________________________ NumPyDiscussion mailing list NumPyDiscussion@scipy.org https://mail.scipy.org/mailman/listinfo/numpydiscussion
Just a heads up, I am planning to put in Stephans pull request (more info, see original mail below) as soon as some minor things are cleared. So if you have any objections or better ideas for the name, now is the time.  Sebastian On Mi, 20151104 at 23:42 0800, Stephan Hoyer wrote:
I've put up a pull request implementing a new function, np.moveaxis, as an alternative to np.transpose and np.rollaxis: https://github.com/numpy/numpy/pull/6630
This functionality has been discussed (even the exact function name) several times over the years, but it never made it into a pull request. The most pressing issue is that the behavior of np.rollaxis is not intuitive to most users: https://mail.scipy.org/pipermail/numpydiscussion/2010September/0528 82.html https://github.com/numpy/numpy/issues/2039 http://stackoverflow.com/questions/29891583/reasonwhynumpyrollaxis issoconfusing
In this pull request, I also allow the source and destination axes to be sequences as well as scalars. This does not add much complexity to the code, solves some additional use cases and makes np.moveaxis a proper generalization of the other axes manipulation routines (see the pull requests for details).
Best of all, it already works on ndarray duck types (like masked array and dask.array), because they have already implemented transpose.
I think np.moveaxis would be a useful addition to NumPy  I've found myself writing helper functions with a subset of its functionality several times over the past few years. What do you think?
Cheers, Stephan _______________________________________________ NumPyDiscussion mailing list NumPyDiscussion@scipy.org https://mail.scipy.org/mailman/listinfo/numpydiscussion
participants (4)

Jonathan Helmus

Juan NunezIglesias

Sebastian Berg

Stephan Hoyer