HomeSoftware EngineeringNormalize a Listing of Numbers in Python

# Normalize a Listing of Numbers in Python

If you want to normalize a listing of numbers in Python, then you are able to do the next:

## Possibility 1 – Utilizing `Native Python`#

``````record = [6,1,0,2,7,3,8,1,5]
print('Unique Listing:',record)
xmin = min(record)
xmax=max(record)
for i, x in enumerate(record):
record[i] = (x-xmin) / (xmax-xmin)
print('Normalized Listing:',record)
``````

## Possibility 2 – Utilizing `MinMaxScaler` from `sklearn`#

``````import numpy as np
from sklearn import preprocessing
record = np.array([6,1,0,2,7,3,8,1,5]).reshape(-1,1)
print('Unique Listing:',record)
scaler = preprocessing.MinMaxScaler()
normalizedlist=scaler.fit_transform(record)
print('Normalized Listing:',normalizedlist)
``````

You can even specify the `vary` of the `MinMaxScaler()`.

``````import numpy as np
from sklearn import preprocessing
record = np.array([6,1,0,2,7,3,8,1,5]).reshape(-1,1)
print('Unique Listing:',record)
scaler = preprocessing.MinMaxScaler(feature_range=(0, 3))
normalizedlist=scaler.fit_transform(record)
print('Normalized Listing:',normalizedlist)
``````
RELATED ARTICLES