[Numpy-discussion] Proposal for a new function: np.moveaxis

Stephan Hoyer shoyer at gmail.com
Thu Nov 5 02:42:15 EST 2015

I've put up a pull request implementing a new function, np.moveaxis, as an
alternative to np.transpose and np.rollaxis:

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:

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?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20151104/9c4e512e/attachment.html>

More information about the NumPy-Discussion mailing list