Python Practice › NumPy Programs › Program 20
3 × 3 identity matrix
Write a NumPy program to create a 3 × 3 identity matrix.
Output
[[1 0 0] [0 1 0] [0 0 1]]
Approach
np.eye(3).
Solution
import numpy as npprint(np.eye(3, dtype=int))Output
[[1 0 0] [0 1 0] [0 0 1]]
Learn the concept
New to this topic? Read the lesson, then come back.