+2 votes
in Class 12 by kratos

Write a Numpy program to create a 3x3 identity matrix, i.e. diagonal elements are 1, the rest are 0. Replace all 0 to random number from 10 to 20

1 Answer

+2 votes
by kratos
 
Best answer

import numpy as np

array1=np.identity(3)

print(array1)

x=np.where(array1==0)

for i in x:

array1[x]=np.random.randint(low=10,high=20)

print(array1)

...