Hello I'd like to ask for a more performance efficient solution for this problem: given two matrices: one with shape (60000, 748) and second with shape (10000, 748) I'd like to iterate over each row in first matrix and for each row in second matrix. Next I'd like to subtract the rows and sum the differences and save them in a "result" matrix. My primitive version is given below.
val = np.array([[0, 2, 4, 2], [2, 4, 1, 5], [3, 3, 1, 9]])
val2 = np.array([[7, 3, 6, 8], [2, 1, 6, 2]])
result = np.zeros((val.shape[0], val2.shape[0]))
for outer_index, validated in enumerate(val):
for inner_index, trained in enumerate(val2):
print(np.absolute(validated - trained).sum(0))
result[outer_index][inner_index] = np.absolute(validated - trained).sum(0)
return result