I think you want to change the line where you calculate d
to something like this:
#Step 10: Euclidean distance
d = np.sqrt(np.sum(np.asarray(w - w_in)**2, axis=1)
This gives you a list of length M
(number of training images) of the squared, summed, rooted distances between each images pixels. I believe that you don't want the matrix product, you want the elementwise square of each value, hence the np.asarray
to make it not a matrix. This gives you the 'euclidean' difference between w_in
and each of the w
matrices.