Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

give the source code in python Problem 1 (2 points): The goal is to compute an N

ID: 3586115 • Letter: G

Question

give the source code in python

Problem 1 (2 points): The goal is to compute an N × N matrix, whose entries are the pairwise Euclidean distance between any two data 1 T 1 -T 1N-1 N-11 N-1N-1 You need to implement two functions 1. The first one, uses a two level nested loop, iterating through all pairs (i,j) and compute the corresponding entry Zi,j 2. The second one, compute Z without any loop, but use matrix operations by numpy. Generate random matrices and profile the performance. Following the given exam ple of entropy computation

Explanation / Answer

              

(a). matrix1 = [[1, 2],

           [5, 8],

       

matrix2 = [[10,13],

           [16,17]]

       

rmatrix = [[0, 0],

        [0, 0]]

for i in range(len(matrix1)):

        for j in range(len(matrix2[0])):

               for k in range(len(matrix2)):

                       rmatrix[i][j] += matrix1[i][k] * matrix2[k][j]

                      

for r in rmatrix:

        print(r)

m1= np.array([7,8])

m2= np.array([1,2])

print m1 *m2