Python Practice › NumPy Programs › Program 19
3 × 3 matrix
Write a NumPy program to create a 3 × 3 matrix.
Output
[[1 2 3] [4 5 6] [7 8 9]]
Approach
arange(9).reshape(3, 3).
Solution
import numpy as npprint(np.arange(1, 10).reshape(3, 3))Output
[[1 2 3] [4 5 6] [7 8 9]]
Learn the concept
New to this topic? Read the lesson, then come back.