linear-algebra-toolkit is a small pure-Python package for experimenting with
core linear algebra operations without NumPy or other numerical libraries.
The codebase is intentionally simple and explicit. It is best suited for learning, reading through the implementation, and running small examples rather than for high-performance scientific computing.
Install the published package from PyPI with:
python -m pip install linear-algebra-toolkitIf you are working from a local checkout, install the project in editable mode with:
python -m pip install -e .- A
Vectortype for one-dimensional numeric data. - A
Matrixtype for two-dimensional numeric data. - Operator overloads for addition, subtraction, element-wise multiplication and
division, and linear algebra products through
@. - A couple of small utility helpers used by the core objects.
- No runtime dependencies outside the Python standard library.
- Keep the implementation readable and easy to inspect.
- Avoid hidden abstractions so the math stays visible in plain Python.
- Provide a compact codebase that is easy to test and extend.
Import the public objects directly from the package:
from linear_algebra_toolkit import Matrix, Vector
vector = Vector([3, 4])
other = Vector([1, 2])
matrix = Matrix([[1, 2], [3, 4]])
print(vector + other) # Vector([4, 6], n elements=2)
print(vector @ other) # 11
print(matrix @ vector) # Vector([11, 25], n elements=2)
print(vector.normalized) # Vector([0.6, 0.8], n elements=2)
print(vector.as_row_matrix())- Construction from a non-empty list of
intandfloatvalues. +and-with vectors of the same shape.+and-with compatible row matrices (1 x n) and column matrices (n x 1).*and/with scalars.- Element-wise
*and/with another vector of the same shape. @with another vector for the dot product.@with a compatible matrix.- Norms through
norm(mode="euclidean" | "manhattan" | "max"). normalized,abs(vector),round(vector, ndigits),as_row_matrix(), andas_col_matrix().
- Construction from a non-empty rectangular list of rows.
+and-with matrices of the same shape.+and-with compatible vectors represented as a row or column.*and/with scalars.- Element-wise
*and/with another matrix of the same shape. @with another compatible matrix.@with a compatible vector.Tfor transpose,norm()for the Frobenius norm,get_row_elements(),get_col_elements(), andget_flatten_elements().
- Only plain Python
intandfloatvalues are accepted. - Division goes through
zero_aware_division(). With the current default configuration, dividing by zero returns0instead of raising an exception. - The project is educational in scope and prioritizes clarity over performance.
From a repository checkout:
python -m unittest discover -s testsThe repository includes a few small scripts in examples/ that demonstrate the
API. From the repository root you can run them like this:
python -m examples.vector_plus_vector
python -m examples.vector_dot_product
python -m examples.matrix_dot_vector
python -m examples.vector_as_matrixlinear_algebra_toolkit/objects.pycontains theVectorandMatriximplementations.linear_algebra_toolkit/utils.pycontains small shared helpers.tests/contains the unit tests for the public behavior.examples/contains runnable usage examples.