-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathminmax.py
32 lines (22 loc) · 883 Bytes
/
minmax.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import numpy as np
'''
This python code calculates the Min-Max Normalization
Min-max normalization is one of the most common ways to normalize data.
For every feature, the minimum value of that feature gets transformed into a 0,
the maximum value gets transformed into a 1, and every other value
gets transformed into a decimal between 0 and 1.
norm = [(x - X.min)/(X.max - X.min)]*(new_max - new_min) + new_min
'''
# Input the data array
data = [200, 400, 800, 1000, 2000]
# Setting the new min and new max
nmin = 0
nmax = 10
# Putting the data in new numpy array
nparray = np.array(data)
#------------- Normalizing the data --------------------------#
# Difference between max nparray value and min nparray value
diff = nparray.max() - nparray.min()
npmin = nparray.min()
ndata = ( (nparray - npmin) / (diff) ) * (nmax-nmin) + nmin
print(ndata)