Matrices

A matrix is a representation of numerical values in two-dimensional space. Much like spreadsheets and tables, it combines several vectors into rows and columns.

Mathematically, a matrix is represented as:

$$ A = \begin{pmatrix} a_{1,1} & a_{1,2} \\ a_{2,1} & a_{2,2} \end{pmatrix} $$

where the sub-positional values represent the location of the value in rows,column positions.

Matrix in Numpy

Creating a simple matrix in numpy

import numpy as np

A = np.array([[3,2], [1, 3]])
A
array([[3, 2], [1, 3]])

A matrix can also be constructed by passing an 1-d array and using the reshaping function to convert a vector into a matrix

B = np.array([3, 2, 1, 3]).reshape(2,2)
B
array([[3, 2], [1, 3]])