1.

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

Answer»

import numpy as np

Z = np.arange(9).reshape(3,3)

print (Z)

x=np.where((Z%2)==0)

for i in x:

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

print(Z) 



Discussion

No Comment Found

Related InterviewSolutions