DATA MUNGING
DATA CLEANING PYTHON
MACHINE LEARNING RECIPES
PANDAS CHEATSHEET
ALL TAGS
# How to calculate Diagonal of a Matrix?

# How to calculate Diagonal of a Matrix?

This recipe helps you calculate Diagonal of a Matrix

Have to tried to calculate diagonal elements and sum of diagonal values.

So this is the recipe on how we can calculate Diagonal of a Matrix.

```
import numpy as np
```

We have only imported numpy which is needed.

We have created a matrix on which we will perform the operation.
```
matrix = np.array([[1, 2, 3, 23],
[4, 5, 6, 25],
[7, 8, 9, 28],
[10, 11, 12, 41]])
```

We can find diagonal elements by the function diagonal and by using sum function we can find the sum of the elements.
```
print(matrix.diagonal())
print(matrix.diagonal().sum())
```

So the output comes as

[ 1 5 9 41] 56

The goal of this data science project is to build a predictive model and find out the sales of each product at a given Big Mart store.

Use the Amazon Reviews/Ratings dataset of 2 Million records to build a recommender system using memory-based collaborative filtering in Python.

Data Science Project in Python- Build a machine learning algorithm that automatically suggests the right product prices.

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.

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.

In this data science project, you will predict borrowers chance of defaulting on credit loans by building a credit score prediction model.

Machine Learning Project in R-Detect fraudulent click traffic for mobile app ads using R data science programming language.

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

In this data science project in R, we are going to talk about subjective segmentation which is a clustering technique to find out product bundles in sales data.

There are different time series forecasting methods to forecast stock price, demand etc. In this machine learning project, you will learn to determine which forecasting method to be used when and how to apply with time series forecasting example.