# numpy.moveaxis() – The NumPy moveaxis Python Function

## Introduction to NumPy moveaxis Python Function

Guide to NumPy moveaxis Python Function – The numpy.moveaxis() function repositions the axes of an array. The order of the other axes remains unchanged.

Syntax:

`numpy.moveaxis(arr, source, destination)`

Parameters:

• arr : [ndarray] input array.
• source : [ int or sequence of int] Original positions of the axes to move. These must be unique.
• destination : [ int or sequence of int] Destination positions for each of the original axes. These must also be unique.

Return: [ndarray] Array with moving axes. This array is a view of the input array.

## Code Examples of NumPy moveaxis Python Function

Example 01:

``````# welcome to softhunt.net
# Python program explaining
# numpy.moveaxis() function

# importing numpy as np
import numpy as np

arr = np.zeros((4, 3, 2, 1))

softhunt = np.moveaxis(arr, 0, -1).shape

print (softhunt)``````

Output:

`(3, 2, 1, 4)`

Example 02:

``````# welcome to softhunt.net
# Python program explaining
# numpy.moveaxis() function

# importing numpy as np
import numpy as np

arr = np.zeros((4, 3, 2, 1))

softhunt = np.moveaxis(arr, -1, 0).shape

print (softhunt)``````

Output:

`(1, 4, 3, 2)`

Note: These programs will not run in online IDEs. Please test them on your systems to see how they operate.

## FAQs

### How do I change the NumPy axis?

1. np.moveaxis(a, sources, destinations) docs. This function can be used to rearrange specific dimensions of an array.
2. np.transpose(a, axes=None) docs. This function can be used to rearrange all dimensions of an array at once.

### What is the axis in NumPy?

For arrays with more than one dimension, axes are define as: A two-dimensional array contains two axes. One that runs vertically downwards across rows (axis 0). And the other runs horizontally across columns (axis 1). (axis 1). One of these axes can be used for a variety of processes.

### How do dimensions work in NumPy?

Dimension is often known as dimensionality. Is the smallest number of coordinates require to specify every point in space in mathematics and physics. However, in Numpy, it’s the same as axis/axes, according to the NumPy doc: Axes are what Numpy calls dimensions. The number of axes determines the rank.

## NumPy moveaxis Python Function: Conclusion

That’s all for this article, if you have any confusion contact us through our website or email us at [email protected] or by using LinkedIn. And make sure you check out our NumPy tutorials.

Suggested Articles:

1. numpy.ndarray.flatten() – The NumPy ndarray flatten Python Function