Answers for "how to normalize a matrix python"

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)
Posted by: Guest on February-12-2021
0

normalize 2d numpy array

import numpy as np

def scale(X, x_min, x_max):
    nom = (X-X.min(axis=0))*(x_max-x_min)
    denom = X.max(axis=0) - X.min(axis=0)
    denom[denom==0] = 1
    return x_min + nom/denom 

X = np.array([
    [ 0,  1],
    [ 2,  3],
    [ 4,  5],
    [ 6,  7],
    [ 8,  9],
    [10, 11],
    [12, 13],
    [14, 15]
])
X_scaled = scale(X, -1, 1)
print(X_scaled)
Posted by: Guest on April-10-2021

Code answers related to "how to normalize a matrix python"

Python Answers by Framework

Browse Popular Code Answers by Language