Reshape the 2×3 matrix into a 2×2 matrix using NumPy.

In this python numpy program, we will reshape the 2×3 matrix into a 2×2 matrix using NumPy.

Steps to solve the program
  1. Import the numpy library as np.
  2. Create a 2×3 matrix using np.array().
  3. Reshape the 2×3 into a 2×2 matrix using reshape.
  4. 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]]
				
			

find the shape of the given matrix.

create a 2×2 zero matrix with elements on the main diagonal equal to 7,8.

Leave a Comment