MACHINE LEARNING RECIPES
DATA CLEANING PYTHON
DATA MUNGING
PANDAS CHEATSHEET
ALL TAGS
# How to create a n by n identity matrix in numpy?

# How to create a n by n identity matrix in numpy?

This recipe helps you create a n by n identity matrix in numpy

Identity matrix are ones having diagonal elements to 1 and rest of elemets to be 0.

So this recipe is a short example on how to create a n by n identity matrix. Let's get started.

```
def identity(n):
m=[[0 for x in range(n)] for y in range(n)]
for i in range(0,n):
m[i][i] = 1
return m
```

In 2nd line, we have created a 0 matrix of size n by n. Thereby, using for loop, updating the diagonal elements.

```
print(identity(3))
```

We are calling identiy function of 3 by 3 matrix. Input needed for the function was 3.

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

[[1, 0, 0], [0, 1, 0], [0, 0, 1]]

In this machine learning and IoT project, we are going to test out the experimental data using various predictive models and train the models and break the energy usage.

Data Science Project - Build a recommendation engine which will predict the products to be purchased by an Instacart consumer again.

Data Science Project in R-Predict the sales for each department using historical markdown data from the Walmart dataset containing data of 45 Walmart stores.

In this machine learning resume parser example we use the popular Spacy NLP python library for OCR and text classification.

Deep Learning Project- Learn to apply deep learning paradigm to forecast univariate time series data.

PySpark Project-Get a handle on using Python with Spark through this hands-on data processing spark python tutorial.

In this machine learning pricing project, we implement a retail price optimization algorithm using regression trees. This is one of the first steps to building a dynamic pricing model.

In this data science project, we will predict the credit card fraud in the transactional dataset using some of the predictive models.

In this machine learning churn project, we implement a churn prediction model in python using ensemble techniques.

This data science in python project predicts if a loan should be given to an applicant or not. We predict if the customer is eligible for loan based on several factors like credit score and past history.