Search⌘ K

Transposing of NumPy Array

In this lesson, transposing of NumPy arrays are explained.

We'll cover the following...

Transpose

As the name suggests, we will take the transpose of a given 2-D NumPy array. Just like matrix transpose in linear algebra, we convert the rows of a 2-D NumPy array into columns and convert its columns into rows. The function transpose() or simply T can be used to take the transpose of a 2-D array.

Python 3.5
import numpy as np
# Creating 2-D array
arr = np.arange(0,50,1).reshape(10,5) # Declare a 2-D array
print("The original array")
print(arr)
print("\nThe transposed array")
print(arr.transpose()) # Print the transposed array
#print(arr.T) # This can also be used and same result will be produced

On line 3, a 2-D array is declared using the arange and reshape ...