A python utility library that models mathematical expressions of matrices.
So what are matrices (or a matrix)?
In layman's terms, a matrix is an array of data, arranged in rows and columns. While matrices may seem very similar to 2-dimensional arrays, they have their own unique set of mathematical operations.
For this project, I used object-oriented python to make a data structure representing a matrix, code for which is available on my github .
I should add that the Array data structure from the famous data science library, NumPy also offers Matrix solutions by default. It is also far more advanced and optimized. So for official use cases, np.array([[1,2], [3,4]])
is far better for representing matrices than my small little library.
How to use it?
Clone the github repository.app.py
from main import Matrix
if __name__ == "__main__":
m1 = Matrix([[1,2],
[3,4]])
m2 = Matrix([[1,2],
[3,4]])
total = m1 + m2
print(total)
This will produce an output of:
Matrix([2, 4]
[6, 8])
It makes use of special methods like __add__
, __sub__
, __mul__
, __truediv__
, __eq__
to make it work.
Matrix dot product is also supported through the .multiply(_Matrix_)
method.
a = Matrix([[1,2,3],
[4,5,6]])
b = Matrix([[1,2],
[3,4],
[5,6]])
c = a.multiply(b)
print(c)
This will produce an output of:
Matrix([22, 28]
[49, 64])
I encourage beginners to go through the source code and try to make sense of what is happening under the hood.