How to normalize a matrix in numpy?
MACHINE LEARNING RECIPES DATA CLEANING PYTHON DATA MUNGING PANDAS CHEATSHEET     ALL TAGS

# How to normalize a matrix in numpy?

This recipe helps you normalize a matrix in numpy

0

## Recipe Objective

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.

## Step 1 - Import the library

``` 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.

## Step 2 - Setup the Data

``` 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.

## Step 3 - Performing Normalization

``` 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.

## Step 4 - Printing matrix

``` print("After normalization:") print(df) ```

We are simply trying to print normalized array in here.

## Step 5 - Lets look at our dataset now

Once we run the above code snippet, we will see:

```Scroll down the ipython notebook to visualize the output.
```

#### Relevant Projects

##### Topic modelling using Kmeans clustering to group customer reviews
In this Kmeans clustering machine learning project, you will perform topic modelling in order to group customer reviews based on recurring patterns.

##### PySpark Tutorial - Learn to use Apache Spark with Python
PySpark Project-Get a handle on using Python with Spark through this hands-on data processing spark python tutorial.

##### Predict Macro Economic Trends using Kaggle Financial Dataset
In this machine learning project, you will uncover the predictive value in an uncertain world by using various artificial intelligence, machine learning, advanced regression and feature transformation techniques.

##### Forecast Inventory demand using historical sales data in R
In this machine learning project, you will develop a machine learning model to accurately forecast inventory demand based on historical sales data.

##### Build an Image Classifier for Plant Species Identification
In this machine learning project, we will use binary leaf images and extracted features, including shape, margin, and texture to accurately identify plant species using different benchmark classification techniques.

##### Perform Time series modelling using Facebook Prophet
In this project, we are going to talk about Time Series Forecasting to predict the electricity requirement for a particular house using Prophet.

##### Deep Learning with Keras in R to Predict Customer Churn
In this deep learning project, we will predict customer churn using Artificial Neural Networks and learn how to model an ANN in R with the keras deep learning package.

##### Sequence Classification with LSTM RNN in Python with Keras
In this project, we are going to work on Sequence to Sequence Prediction using IMDB Movie Review Datasetâ€‹ using Keras in Python.

##### Predict Churn for a Telecom company using Logistic Regression
Machine Learning Project in R- Predict the customer churn of telecom sector and find out the key drivers that lead to churn. Learn how the logistic regression model using R can be used to identify the customer churn in telecom dataset.

##### Demand prediction of driver availability using multistep time series analysis
In this supervised learning machine learning project, you will predict the availability of a driver in a specific area by using multi step time series analysis.