Using norms instead of distances

In the first lab of week 1 (Exercise 1), when we have to minimize the distances to find the best cluster centroid, according the formula we have to check the distances by ||x(i) - Uk || ** 2, to implement the same I used the following code

Allbeit there are some syntactical errors, ignoring them conceptually I can’t understand what’s wrong with this way, and the solution used something called norm from linear algebra, what is that and how is that related to the distance. Thanks you

The first thing I see that concerns me is that your “elem” is a scalar value, but you’re using .append to add it to a 2D “dist” matrix.

The append() method has no idea where you want (row and column) the ‘elem’ value stored.

Also, just a friendly reminder - please don’t post your code on the forums. That’s not allowed by the course Code of Conduct.

If a mentor needs to see your code, we’ll contact you with instructions.