NumPy reshape

  • Post category:NumPy

In this NumPy tutorial, you’ll learn how to use the NumPy reshape 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)

# reshape the array
var = var.reshape(3, 2)

# print the array
print(var)

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

Output:

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

Free resources to learn advanced skills: AiHints and CodeAllow