Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the numpy.linalg.norm function?

What is the function of numpy.linalg.norm method?

In this Kmeans Clustering sample the numpy.linalg.norm function is used to get the distance between new centroids and old centroids in the movement centroid step but I cannot understand what is the meaning by itself

Could somebody give me a few ideas in relation to this Kmeans clustering context?

What is the norm of a vector?

like image 894
bgarcial Avatar asked May 13 '26 15:05

bgarcial


1 Answers

I am not a mathematician but here is my layman's explanation of “norm”:

A vector describes the location of a point in space relative to the origin. Here’s an example in 2D space for the point [3 2]:

Point in 2D space

The norm is the distance from the origin to the point. In the 2D case it’s easy to visualize the point as the diametrically opposed point of a right triangle and see that the norm is the same thing as the hypotenuse.

Point in 2D space showing relationship between norm and hypotenuse

However, In higher dimensions it’s no longer a shape we describe in average-person language, but the distance from the origin to the point is still called the norm. Here's an example in 3D space:

Point in 3D space showing the norm

I don’t know why the norm is used in K-means clustering. You stated that it was part of determing the distance between the old and new centroid in each step. Not sure why one would use the norm for this since you can get the distance between two points in any dimensionality* using an extension of the from used in 2D algebra:

Formula for distance between 2 points in 2D space

You just add a term for each addtional dimension, for example here is a 3D version:

Formula for distance between 2 points in 3D space

*where the dimensions are positive integers

like image 179
Robb Dunlap Avatar answered May 16 '26 06:05

Robb Dunlap