matrix normalization numpy code example
Example 1: numpy normalize
def normalize(v):
norm = np.linalg.norm(v)
if norm == 0:
return v
return v / norm
Example 2: numpy normalize matrix
import numpy as np
x= np.random.random((3,3))
print("Original Array:")
print(x)
xmax, xmin = x.max(), x.min()
x = (x - xmin)/(xmax - xmin)
print("After normalization:")
print(x)