In this python numpy program, we will create a 2×2 zero matrix with elements on the main diagonal equal to numbers.
Steps to solve the program
- Import the numpy library as np.
- Create a 2×2 zero matrix with elements on the main diagonal using np.diag().
- Print the output.
import numpy as np
x = np.diag([7,8])
print(x)
Output :
[[7 0]
[0 8]]