Search code examples
pythonnumpyk-means

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?


Solution

  • numpy.linalg.norm is used to calculate the norm of a vector or a matrix.


    This is the help document taken from numpy.linalg.norm:

    numpy.linalg.norm(x, ord=None, axis=None, keepdims=False)[source]
    

    enter image description here


    This is the code snippet taken from K-Means Clustering in Python:

    # Euclidean Distance Caculator
    def dist(a, b, ax=1):
        return np.linalg.norm(a - b, axis=ax)
    

    It take order=None as default, so just to calculate the Frobenius norm of (a-b), this is ti calculate the distance between a and b( using the upper Formula).