Math for Data Science — Lecture 01 Basic Matrix Operations via Python

In this lecture, we will study Matrix Operations (Initialization, Vector, Multiplication, Transpose, Special Matrix) via Python.

Matrix Definition

Image 01: Matrix Definition

Matrix Notation

Image 02: Matrix Notation

Matrix Initialization

import numpy as np
print(np.zeros((2,3)))
print(np.random.randint(low = 5,high=12, size=(2, 3)))
A = np.matrix([[1, 2], [3, 4], [5,6]])
print("Type of Matrix A:{}, having {} rows and {} columns".format(type(A),A.shape[0],A.shape[1]))
Image 03: Matrix Initialization — code

Vectors

Image 04: Vector Definition
  • Row vector is having 1 row and N columns
  • Column vector is having N rows and 1 column
Image 05: Row and Column Vector — code
Image 06: Convert Row vector to Column Vector — code

Matrix Equality

Image 07: Check Matrix Equality — code

Matrix Multiplication

Image 08: Matrix Multiplication Shape

In below Image 09, matrix multiplication is shown both via python code and hand as well.

Image 09: Matrix Multiplication calculation by hand
  • Matrix multiplication isn’t commutative (AB != BA)
Image 10: Matrix Not Commutative — code

Matrix Transpose

Image 11: Matrix Transpose — code

Rules of Matrix Transpose

Image 12.1: Rules of Matrix transpose — code
Image 12.2: Rules of Matrix transpose — code

Special Matrix

Image 13: Special Matrices Definition
Image 14: Check if Special Matrix — code
Image 15: Caller Function (Special Matrix) — code

Reduce size of Sparse Matrix using CSR (Compressed Sparse Row)

Image 16: Dense and Sparse Matrix storage comparison — code

Properties of Determinants

Image 17: Properties of Determinants

WORK IN PROGRESS !! Jupyter Notebook/.py will be uploaded soon..

Our Next lecture is about using Elementary row operations to find Row Echelon Form (REF), Reduced Row Echelon Form (RREF) and Rank of Matrix (https://medium.com/math-for-data-science/math-for-data-science-lecture-02-elementary-row-operations-via-python-46885a33a84c).

Meanwhile, Please feel free to clap if you liked the article. Also, please subscribe to my YouTube Channel https://www.youtube.com/channel/UC4yh4xPxRP0-bLG_ldnLCHA?sub_confirmation=1

--

--

--

Idea is to understand math for data science from intuition and code (mainly python)

Recommended from Medium

A beginner’s approach to Solve a Data Science Problem

Graph Algorithms for Risk Assessment

Predictive Modeling in Healthcare Analytics

Data Visualization Capstone Project

Positivity rate in 1/3 of districts higher than Punjab average | Chandigarh News — Times of India

Data Scientist to Product Manager? It’s not a common path, they say

TUTORIAL SERIES: 6 CHARACTERISTICS OF SUCCESSFUL TRADERS

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Aakash Goel

Aakash Goel

Senior Data Scientist @ Fractal Analytics

More from Medium

Exploring Singular Value Decomposition(SVD) from scratch in python

Data Science 🤝 Math (Linear algebra)

The Zeta transform: definition, theorems, examples — The Tech Goggler

Python for Data Science — NumPy