Normalization using numpy.linalg.norm

The NumPy library provides a method called norm that returns one of eight different matrix norms or one of an infinite number of vector norms. It entirely depends on the ord parameter in the norm method. By default, the norm considers the Frobenius norm. The data here is normalized by dividing the given data with the returned norm by the norm method.

Python3




# import necessary packages
import numpy as np
  
# create an array
data = np.array([[10, 20], [30, 40],
                 [5, 15], [0, 10]])
  
normalizedData = data/np.linalg.norm(data)
  
# normalized data using linalg.norm
print(normalizedData)


Output

[[0.17277369 0.34554737]
 [0.51832106 0.69109474]
 [0.08638684 0.25916053]
 [0.         0.17277369]]

How to normalize an NumPy array so the values range exactly between 0 and 1?

In this article, we will cover how to normalize a NumPy array so the values range exactly between 0 and 1.

Normalization is done on the data to transform the data to appear on the same scale across all the records. After normalization, The minimum value in the data will be normalized to 0 and the maximum value is normalized to 1. All the other values will range from 0 to 1. Normalization is necessary for the data represented in different scales. Because Machine Learning models may get over-influenced by the parameter with higher values. There are different ways to normalize the data. One of the standard procedures is the min-max value approach.

Similar Reads

Normalization using Min Max Values

Here normalization of data can be done by subtracting the data with the minimum value in the data and dividing the result by the difference between the maximum value and the minimum value in the given data. we will look into more deep to the code for a better understanding....

Normalization using sklearn MinMaxScaler

...

Normalization using numpy.linalg.norm

In Python, sklearn module provides an object called MinMaxScaler that normalizes the given data using minimum and maximum values. Here fit_tranform method scales the data between 0 and 1 using the MinMaxScaler object....

Normalization using Maths Formula

...