In this python numpy program, we will reshape the 2×3 matrix into a 2×2 matrix using NumPy.
Steps to solve the program
- Import the numpy library as np.
- Create a 2×3 matrix using np.array().
- Reshape the 2×3 into a 2×2 matrix using reshape.
- Print the output.
import numpy as np
x = np.array([[5,6,7],
[8,9,10]])
y = x.reshape(3,2)
print(y)
Output :
[[ 5 6]
[ 7 8]
[ 9 10]]