Python Practice › NumPy Programs › Program 20

3 × 3 identity matrix

EasyNumPy Programs · 20 of 100

Write a NumPy program to create a 3 × 3 identity matrix.

Advertisement
Output
[[1 0 0]
 [0 1 0]
 [0 0 1]]

Approach

  1. np.eye(3).

Solution

Python
import numpy as npprint(np.eye(3, dtype=int))
Output
[[1 0 0]
 [0 1 0]
 [0 0 1]]
Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More numpy programs

← All 100 NumPy Programs