- NumPy Tutorial
- NumPy - Home
- NumPy - Introduction
- NumPy - Environment
- NumPy - Ndarray Object
- NumPy - Data Types
- NumPy - Array Attributes
- NumPy - Array Creation Routines
- NumPy - Array from Existing Data
- Array From Numerical Ranges
- NumPy - Indexing & Slicing
- NumPy - Advanced Indexing
- NumPy - Broadcasting
- NumPy - Iterating Over Array
- NumPy - Array Manipulation
- NumPy - Binary Operators
- NumPy - String Functions
- NumPy - Mathematical Functions
- NumPy - Arithmetic Operations
- NumPy - Statistical Functions
- Sort, Search & Counting Functions
- NumPy - Byte Swapping
- NumPy - Copies & Views
- NumPy - Matrix Library
- NumPy - Linear Algebra
- NumPy - Matplotlib
- NumPy - Histogram Using Matplotlib
- NumPy - I/O with NumPy
- NumPy Useful Resources
- NumPy Compiler
- NumPy - Quick Guide
- NumPy - Useful Resources
- NumPy - Discussion
numpy.swapaxes
This function interchanges the two axes of an array. For NumPy versions after 1.10, a view of the swapped array is returned. The function takes the following parameters.
numpy.swapaxes(arr, axis1, axis2)
Where,
Sr.No. | Parameter & Description |
---|---|
1 | arr Input array whose axes are to be swapped |
2 | axis1 An int corresponding to the first axis |
3 | axis2 An int corresponding to the second axis |
Example
# It creates a 3 dimensional ndarray import numpy as np a = np.arange(8).reshape(2,2,2) print 'The original array:' print a print '\n' # now swap numbers between axis 0 (along depth) and axis 2 (along width) print 'The array after applying the swapaxes function:' print np.swapaxes(a, 2, 0)
Its output would be as follows −
The original array: [[[0 1] [2 3]] [[4 5] [6 7]]] The array after applying the swapaxes function: [[[0 4] [2 6]] [[1 5] [3 7]]]
numpy_array_manipulation.htm
Advertisements