DATA MUNGING
DATA CLEANING PYTHON
MACHINE LEARNING RECIPES
PANDAS CHEATSHEET
ALL TAGS
# How to calculate Diagonal of a Matrix using numpy in python

This recipe helps you calculate Diagonal of a Matrix using numpy in python

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

**
Download Materials
**

Use the Zillow dataset to follow a test-driven approach and build a regression machine learning model to predict the price of the house based on other variables.

In this Project we will Monitoring the Real-Time cab service and How to Handle these using Azure Stream Analytics and Power Bi

FEAST Feature Store Example- Learn to use FEAST Feature Store to manage, store, and discover features for customer churn prediction machine learning project.

MLOps on GCP - Solved end-to-end MLOps Project to deploy a Mask RCNN Model for Image Segmentation as a Web Application using uWSGI Flask, Docker, and TensorFlow.

In this time series project, you will forecast Walmart sales over time using the powerful, fast, and flexible time series forecasting library Greykite that helps automate time series problems.

In this loan prediction project you will build predictive models in Python using H2O.ai to predict if an applicant is able to repay the loan or not.

Learn the basic aspects of chatbot development and open source conversational AI RASA to create a simple AI powered chatbot on your own.

In this OpenCV project, you will learn computer vision basics and the fundamentals of OpenCV library using Python.

In this ensemble machine learning project, we will predict what kind of claims an insurance company will get. This is implemented in python using ensemble machine learning algorithms.

In this deep learning project, you will build your own face recognition system in Python using OpenCV and FaceNet by extracting features from an image of a person's face.