matrices repository was created to provide basic operation on matrices: addition, multiplication, transposition, reversion etc(check all operation below). Project, mostly, has educational purpose and will be useful for students(it contains examples how to implement matrices operation in python, and also examples of possible pitfalls due to 'bad' implementation). Need to mention, that main script('matrices.py') follow PEP8 convention.
To use 'matrices' in your own project - just copy 'matrices.py' and 'errors.py' in your project directory. Then, use import statement like this:
import matrices
To provide more acurate calculation, matrices module using decimal type of numbers. So, to initialize a new Matrix instance, you need to pass into constructor a list of lists, that consist of decimal arguments or other numeric type arguments(they will be convert into decimal type inside a constructor). Example:
import matrices
list_of_lists = [[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]
A = matrices.Matrix(list_of_lists)
C = A + B
B = A.multiply_by_number(k, precision)
B = A * k - note: cant use precision parameter explicitly(using default value).
C = A - B
B = A.divide_by_number(k, precision)
B = A/k - note: cant use precision parameter explicitly(using default value).
C = A * B
det = A.matrix_determinant(precision)
B = A.matrix_inverse(precision)
B = A + k
B = A - k
If you want to initialize a Zero matrix with a given sizes - use a child class of Matrix: ZeroMatrix(). It takes 2 'must be' parameters(plus one optional): number of rows('m' - integer number) and number of columns('n' integer number). Example:
O = matrices.ZeroMatrix(m, n)If you need to fill the matrix with same number, different from zero -
use optional parameter 'number' of ZeroMatrix() class, like this:
O = matrices.ZeroMatrix(m, n, number=k), where k - numeric type. For example:
O = matrices.ZeroMatrix(2, 2, number=-4.2) will create 2 by 2 matrix filled with number -4.2
For initializing an Identity matrix - use subclass IdentityMatrix(). Here you need to pass one parameter - matrix dimension (n - integer digit, which represent numbers of rows/columns for square matrix). Example:
I = matrices.IdentityMatrix(n)