Assume a and b are two (20, 20) numpy arrays. The L2-distance (defined above) between two equal dimension arrays can be calculated in python as follows:
def l2_dist(a, b):
result = ((a - b) * (a - b)).sum()
result = result ** 0.5
return result
Which of the following expressions using this function will give an error?
l2_dist(np.reshape(a, (20 * 20)), np.reshape(b, (20 * 20, 1)))
l2_dist(np.reshape(a, (20 * 20)), np.reshape(b, (20 * 20, 1)))
# expression is correct, none of the operators will cause an error
# errors are possible if the module is not imported:
import numpy as np
# or arrays a,b are not defined in the program, but these cases are trivial and can be ignored
Comments
Leave a comment