In [1]:
import statistics
import pprint
In [2]:
l = [0, 1, 2, 3, 4]
In [3]:
print(l)
In [4]:
def min_max(l):
l_min = min(l)
l_max = max(l)
return [(i - l_min) / (l_max - l_min) for i in l]
In [5]:
print(min_max(l))
In [6]:
def standardization(l):
l_mean = statistics.mean(l)
l_stdev = statistics.stdev(l)
return [(i - l_mean) / l_stdev for i in l]
In [7]:
pprint.pprint(standardization(l))
In [8]:
def standardization_p(l):
l_mean = statistics.mean(l)
l_pstdev = statistics.pstdev(l)
return [(i - l_mean) / l_pstdev for i in l]
In [9]:
pprint.pprint(standardization_p(l))
In [10]:
l_2d = [[0, 1, 2], [3, 4, 5], [6, 7, 8]]
In [11]:
print(l_2d)
In [12]:
pprint.pprint([min_max(l_1d) for l_1d in l_2d], width=40)
In [13]:
pprint.pprint([standardization(l_1d) for l_1d in l_2d], width=40)
In [14]:
pprint.pprint([standardization_p(l_1d) for l_1d in l_2d])
In [15]:
l_2d_min_max_col = list(zip(*[min_max(l_1d) for l_1d in list(zip(*l_2d))]))
In [16]:
pprint.pprint(l_2d_min_max_col, width=40)
In [17]:
l_2d_standardization_col = list(zip(*[standardization(l_1d) for l_1d in list(zip(*l_2d))]))
In [18]:
pprint.pprint(l_2d_standardization_col, width=40)
In [19]:
l_2d_standardization_p_col = list(zip(*[standardization_p(l_1d) for l_1d in list(zip(*l_2d))]))
In [20]:
pprint.pprint(l_2d_standardization_p_col)
In [21]:
def min_max_2d_all(l_2d):
l_flatten = sum(l_2d, [])
l_2d_min = min(l_flatten)
l_2d_max = max(l_flatten)
return [[(i - l_2d_min) / (l_2d_max - l_2d_min) for i in l_1d]
for l_1d in l_2d]
In [22]:
pprint.pprint(min_max_2d_all(l_2d), width=40)
In [23]:
def standardization_2d_all(l):
l_flatten = sum(l_2d, [])
l_2d_mean = statistics.mean(l_flatten)
l_2d_stdev = statistics.stdev(l_flatten)
return [[(i - l_2d_mean) / l_2d_stdev for i in l_1d]
for l_1d in l_2d]
In [24]:
pprint.pprint(standardization_2d_all(l_2d))
In [25]:
def standardization_p_2d_all(l):
l_flatten = sum(l_2d, [])
l_2d_mean = statistics.mean(l_flatten)
l_2d_pstdev = statistics.pstdev(l_flatten)
return [[(i - l_2d_mean) / l_2d_pstdev for i in l_1d]
for l_1d in l_2d]
In [26]:
pprint.pprint(standardization_p_2d_all(l_2d))