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