NumPy transpose

  • Post category:NumPy

In this NumPy tutorial, you’ll learn how to use the NumPy transpose function in Python.

# import numpy module
import numpy as np

# create a numpy array
var = np.array([[11, 22, 33], [44, 55, 66]])

# print the array
print(var)

# print the shape of the array
print(var.shape)

# transpose the array
var = var.T

# print the array
print(var)

# print the shape of the array
print(var.shape)

Output:

[[11 22 33]
 [44 55 66]]
(2, 3)
[[11 44]
 [22 55]
 [33 66]]
(3, 2)

Free resources to learn advanced skills: AiHints and CodeAllow