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