Normalization is a process of organizing the data in a database to avoid data redundancy, insertion anomaly, update anomaly & deletion anomaly. Many a times, it becomes unavoidable when dealing with large datasets especially image processing.
So this recipe is a short example on how to to normalize matrix in numpy. Let's get started.
import numpy as np
Let's pause and look at these imports. Numpy is generally helpful in data manipulation while working with arrays. It also helps in performing mathematical operation.
df= np.random.random((3,3)) print("Original Array:") print(df)
We have a created a simple 3x3 matrix in form of an array, containing random values.
dfmax, dfmin = df.max(), df.min() df = (df - dfmin)/(dfmax - dfmin) print(df)
For normalization, the calculation follows as subtracting each element by minimum value of matrix and thereby dividing the whole with difference of minimum and maximum of whole matrix.
print("After normalization:") print(df)
We are simply trying to print normalized array in here.
Once we run the above code snippet, we will see:
Scroll down the ipython notebook to visualize the output.