I am learning Numpy. How do i get the expected output from identity matrix
identity matrix
1, 0, 0
0, 1, 0
0, 0, 1
Expected Output :
1, 0, 0
0, 0, 0
0, 0, 0
>Solution :
Your question is unclear, however assuming you have a matrix of zeros with 1’s on the diagonal and want to have all zeros but the first element:
a = np.array([[1,0,0],
[0,1,0],
[0,0,1]])
np.fill_diagonal(a, 0)
a[0,0] = 1
output:
array([[1., 0., 0.],
[0., 0., 0.],
[0., 0., 0.]])