Published on January 26, 2024By DeveloperBreeze
Python Example: Reshaping Arrays with NumPy
The following Python code demonstrates how to reshape a one-dimensional array into a two-dimensional array using NumPy:
import numpy as np
# Define a one-dimensional array
arr = np.array([1, 2, 3, 4, 5, 6])
# Reshape the array into a 2x3 matrix
reshaped_arr = arr.reshape(2, 3)
print(reshaped_arr)
Comments
Please log in to leave a comment.