1>>> mu, sigma = 0, 0.1 # mean and standard deviation
2>>> s = np.random.normal(mu, sigma, 1000)
3
1# Foe 1d array
2an_array = np.array([0.1,0.2,0.3,0.4,0.5])
3
4norm = np.linalg.norm(an_array)
5normal_array = an_array/norm
6print(normal_array)
7
8#[0.2,0.4,0.6,0.8,1] (Should be, I didin't run the code)
1def normalize(v):
2 norm = np.linalg.norm(v)
3 if norm == 0:
4 return v
5 return v / norm
6
1import numpy as np
2x= np.random.random((3,3))
3print("Original Array:")
4print(x)
5xmax, xmin = x.max(), x.min()
6x = (x - xmin)/(xmax - xmin)
7print("After normalization:")
8print(x)
9
1 norm = np.linalg.norm(an_array_to_normalize)
2
3 normal_array = an_array_to_normalize/norm
4
5or for pixels to be obtained in my case. This can be used to map values to another scale from the current scale of values.
6
7 scaled_array = (array/np.float(np.max(array)) )*255.