Saturday, March 11, 2023
HomeSoftware EngineeringFind out how to Normalize a Checklist of Numbers in Python

# Find out how to Normalize a Checklist of Numbers in Python

If it’s good to normalize an inventory of numbers in Python, then you are able to do the next:

## Possibility 1 – Utilizing `Native Python`#

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

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

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

It’s also possible to specify the `vary` of the `MinMaxScaler()`.

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