Answer:
import numpy as np
# creating matrix of order 10*10 with random numbers between 1 and 20
m = np.random.randint(1,20, size=(10,10))
# create new matrix which reads matrix m and produces zero along the diagonal
n = np.random.randint(1,20, size=(10,10)) # create new matrix, n
for i in range(0,10): # loop through row of matrix
for j in range(0,10): # loop through column of the matrix
if i==j: # check for the diagonal element
n[i][j] = 0 # asign diagonal value to zero
else:
n[i][j] = m[i][j] # assign the value of matrix m to n
# displaying m and n matrix in the given format using disp function
from io import StringIO
buf = StringIO()
np.disp(m,device=buf)
m = buf.getvalue()
m = m[1:-1] #removing the extra [ and ]from beginning and end
print("m = ")
print(m.replace(" [","").replace('[',"").replace(']',""))
buf = StringIO()
np.disp(n,device=buf)
n = buf.getvalue()
n = n[1:-1] #removing the extra [ and ]from beginning and end
print("n = ")
print(n.replace(" [","").replace('[',"").replace(']',""))
Explanation: