Skip to main content

A package implementing matrices

Project description

Matrix and Vector Algebra

Python list to contain elements in matrices

A base class matrix implementing linear algebra matrices and typical operations, as well as child class vector with more specific operations for euclidean vectors.

Installation

python3 -m pip install matrix-henryj

Documentation

Example

Code:

A = Matrix(2,2)
b = Matrix(2,1)
A.setVals([1,3,0,1])
b.setVals([1,1])
print(A*b)

Output:

 _        _
|  4.0000  |
|  1.0000  |
 ‾        ‾
  • class Matrix:
    • __init__(self,rows,columns)
    • setVals(self,values)
    • zero(self)
    • ID(self)
    • __str__(self)
    • __add__(self,other)
    • __mul__(self,other)
    • __rmul__(self,other)
    • __truediv__(self,other)
    • __neg__(self)
    • __sub__(self,other)
    • __pow__(self,factor)
    • __mod__(self,other)
    • __eq__(self,other)
    • __getitem__(self,index)
    • size(self)
    • Transpose(self)
    • Trace(self)
    • combMat(self,other)
    • splitMat(self,col)
    • __rowSwap(self,row1,row2,factor)
    • __rowAdd(self,row1,row2,factor)
    • __rowMult(self,row,factor)
    • solveLin(self,other)
    • __gaussElimination(self,other)
    • __jordanElimination(self,other)
    • det(self)
  • class Vector(Matrix):
    • __init__(self,rows)
    • __mul__(self,other)
    • cross(self,other)
    • length(self,other)
    • scalarProj(self,other)
    • Normalize(self)

class Matrix

A class implementing linear algebra matrices and typical functions available for matrices.

__init__(self,other)

Initialize matrix with a number of rows and columns.

setVals(self,values)

Give values to matrix in list values row by row left to right.

zero(self)

Makes the matrix a zero matrix.

ID(self)

Makes the matrix an identity matrix.

__str__(self)

Defines string of matrix object.

__add__(self,other)

Returns addition of two matrices.

__mul__(self,other)

Returns multiplication of two matrices or a matrix with a factor.

__rmul(self,other)

Returns multiplication of two matrices or a matrix with a factor, same as __mul__.

__truediv__(self,other)

Returns multiplication by other inverse to the right or division by factor.

__neg__(self)

Returns changed sign of all values in matrix.

__sub__(self,other)

Returns difference of two matrices.

__pow__(self,factor)

Raises a matrix to an whole number or takes inverse if factor is negative one.

__mod__(self,other)

Returns multiplication of self inverse from the right to other if matrix, otherwise takes modulus of each element in self.

__eq__(self,other)

Checks if matrices are equal at every position.

__getitem(self,other)

The value at the index in the matrix, counting by rows first.

size(self)

The size of the matrix in a list, columns and rows.

Transpose(self)

Returns transpose of the matrix, swapping rows with columns.

Trace(self)

Returns the trace of the matrix, sum of all diagonal elements.

combMat(self,other)

Returns the two matrices in a singular matrix, side by side.

splitMat(self,col)

Splits the matrix by column col and returns the objects in a list.

__rowSwap(self,row1,row2)

Swaps places of row1 and row2.

__rowAdd(self,row1,row2,factor)

Adds row2*factor to row1.

__rowMult(self,row,factor)

Multiplies a row by factor.

solveLin(self,other)

Solves self*x=other and returns x for each solution for each column in other.

__gaussElimination(self,other)

Returns the gaussian elimination of self and other in self*x = other.

__jordanElimination(self,other)

Returns the jordan elimination of self and other in self*x = other.

det(self)

Calculates the determinant using gaussian elimination.

class Vector(Matrix)

A class implementing euclidean vectors and typical operations you can do with them.

__init__(self,rows)

Initializes a vector with a number of rows.

__mul__(self,other)

Returns the dot product of two vectors or multiplication of each element by a number.

cross(self,other)

Returns the cross product of the two vectors.

length(self)

Returns the euclidean vector length.

scalarProj(self,other)

Returns the scalar projection of self onto other.

Normalize(self)

Return a vector of length one in same direction.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

matrix-henryj-1.0.0.tar.gz (6.5 kB view details)

Uploaded Source

File details

Details for the file matrix-henryj-1.0.0.tar.gz.

File metadata

  • Download URL: matrix-henryj-1.0.0.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.6.9

File hashes

Hashes for matrix-henryj-1.0.0.tar.gz
Algorithm Hash digest
SHA256 080e35982234a1581d7288673b7f4372807e9abf30cd4075f396b7f0cd4b3c6d
MD5 d9a19a454c59882a9f2b3f094cc9955d
BLAKE2b-256 be191a44643f4bcde979622f5eb7c475ec21a97fc8ea4fefdb67887083aab31f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page