Vector/Matrix classes - refined rref and fixed a bug. Added author information.
Project description
linear-algebra-ulloa
implemented vector and matrix classes with reST-formatted docstrings in Python 3+
General Layout
The Vector class imitates the m x 1 vector from linear algebra and contains many useful functions for dealing and interacting with Vectors.
Getting values directly from the vector should be done using the get(index) function or [] operator since the comp vector location in memory may change with functions like mag() or zero() (those which change current vector comp).
class Vector
__init__(comp) - takes in a list of components or a valid mx1 Matrix
resize(length) - while preserving current elements or filling with 0's, changes current vector length
set(comp, index=-1) - sets entire list at once or one specific index/value
get(index) - returns item at specified index of vector
zero() - turns the current vector into a zero vector and returns it
mag() - returns the magnitude of current vector
normalize(change=False) - returns normalized current vector, if change=True, internal vector is updated
same_normalized(other) - returns True/False depending on equality of the two vectors once normalized
dot(other) - returns the dot product of th two vectors
cross(other) - returns the cross product of u x v (u is current vector, v is other)
perp(other) - returns True/False if current and other are/aren't perpendicular
parallel(other) - returns True/False if current and other are/aren't parallel
indep(other) - returns True/False if curr vector and other vector(s) are linearly independent
operator + - returns sum of two vectors, component wise addition
operator - - returns difference of two vectors, component wise subtraction
operator * - alternate for dot product, or can use for vector scaling
operator ** - returns original vector with its components raised to power
operator == - checks to see if lists are equal
to string method - format: "<elem1, elem2, ...>"
len() method - can use len() to get vector length
get and set [] - user can get and set values in vector with index based operations []
comp = vector composition, list of components
length = number of components in vector
rows = same as length, used with cols for backwards compatibility with Matrix
cols = 1 (num of columns)
The Matrix class imitates the matrix concept from linear algebra and allows for different ways of dealing and interacting with matrices and vectors.
Getting values directly from the vector should be done using the get(row, col) function or [], [][] operator since the matrix comp location in memory may change with functions that change the underlying data type.
class Matrix
__init__(comp) - takes in a list of components or a valid Vector
resize(rows, cols) - while preserving current elements or filling with 0's, changes current vector length
set(comp, index=None) - sets entire list at once or one specific index/value (tuple or array as (row, col))
get(row=None,col=None) - can get a specific row, column, or entire matrix composition (no args for matrix)
zero() - replaces values in current matrix with all zeroes and returns it
det() - takes the determinant of the current NxN matrix
transpose() - transposes the current mxn matrix to an nxm matrix (1st row becomes 1st col, etc.)
row_echelon() - returns the current matrix in row echelon form
row_reduce() - returns the current matrix to reduced row echelon form
identity(n) - static method that returns the nxn identity matrix
combine(first, second) - static method that combines two matrices by concatenation
inverse() - returns the inverse of current nxn matrix, or None if singular
operator + - returns sum of two matrices, component wise addition
operator - - returns difference of two matrices, component wise subtraction
operator * - matrix multiplication, matrix-vector product, scalar multiplication
operator ** - returns original matrix with its components raised to power
operator == - checks to see if internal lists are equal
to string method - format: "[row1\n row2\n row3\n ...]" and floats are shown as fractions
len() method - returns tuple formatted as (row, col)
get and set [][] - can get rows and specific values with [] or [][], and set specific values with [][]
comp = matrix composition, list of lists where each list is a row
rows = number of rows in matrix
cols = number of columns in matrix
Tests
There is a file for writing tests. At the moment, it is only a series of assertions. In the future, I will update the testing file to use a more standardized version/library for testing.
Docstrings/Documentation
There is thorough documentation throughout the library. Python library contains a help() function that could be used to view the docstrings for a specific class/method.
Class: help(classname)
Method: help(classname.methodname)
For example, help(Vector.resize) shows you ...
resize(self, length)
Re-sizes the vector to the specified length. If length is greater than
current size, the new components are initialized with 0, otherwise if length
is less than current size, the last few components are lost.
:param length: new length of vector
:type length: int
:return: current vector, now resized
:rtype: Vector
and vice versa. help(Vector) and help(Matrix) return major class overviews.
Using library
pip:
pip install linear-algebra-ulloa
or
pip3 install linear-algebra-ulloa
Use
from linear_lib.linear import *
to be able to create and utilize vector and matrix classes without the linear.Vector or linear.Matrix prefix.
Potential additions to library in future
Vector Class
-
Method for checking if current vector and other vector are orthogonal -
Support for plotting/graphing a certain amount of 2D maybe 3D vectors using matplotlib or a similar library
-
Cross products
Matrix Class
-
Determinant -
Row Reducing Matrices -
Finding inverse of Matrices -
Transposing matrices -
Standalone function for fitting a straight line with least squares approximation
-
General least squares method as part of matrices class
Additional
-
index access with [] [][] operator -
identify whether a set of vectors are linearly independent -
identify whether two vectors are parallel -
static method for generating arbitrarily sized identity matrix -
static method for concatenating two matrices -
floats are shown as proper fractions when printed -
equality tests account for floating point error
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file linear_algebra_ulloa-0.0.2.tar.gz
.
File metadata
- Download URL: linear_algebra_ulloa-0.0.2.tar.gz
- Upload date:
- Size: 15.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5485a8717016e2819b5548e28a03a06c5c03f72cdf273ad982ddcf842708581d |
|
MD5 | 91f3ffcc4e1bbc1cb5eff4620dbce14b |
|
BLAKE2b-256 | ddc3f7184675dcd58d9214d660b703c3a19ac9579159b338ebd297820fcd5830 |
File details
Details for the file linear_algebra_ulloa-0.0.2-py3-none-any.whl
.
File metadata
- Download URL: linear_algebra_ulloa-0.0.2-py3-none-any.whl
- Upload date:
- Size: 16.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 05852fa2dd1d908aed2d66979a152a4d434bb5b436713945ab2cf6e78feb4d3a |
|
MD5 | 2c5493153d7867074218d1974d5bd633 |
|
BLAKE2b-256 | 548dd92d0a351a8bd774c57369ab43a19e8b5ea434ad6a2cf7474afbbf5a2853 |