In this python numpy program, we will create a 2×2 matrix using NumPy.
Steps to solve the program
- Import the numpy library as np.
- Create an array of 4 elements using np.array() because 2×2 matrix will have 4 elements.
- Now convert the array to create a 2×2 matrix using reshape.
- Print the output.
import numpy as np
x = np.arange(4)
x.reshape(2,2)
Output :
array([[0, 1],
[2, 3]])