Skip to main content

Educational pure-Python vector and matrix objects for linear algebra experiments.

Project description

Linear Algebra Toolkit

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.

Installation

Install the published package from PyPI with:

python -m pip install linear-algebra-toolkit

If you are working from a local checkout, install the project in editable mode with:

python -m pip install -e .

What the project provides

  • A Vector type for one-dimensional numeric data.
  • A Matrix type 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.

Design goals

  • 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.

Quick start

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())

Supported operations

Vector

  • Construction from a non-empty list of int and float values.
  • + 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(), and as_col_matrix().

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.
  • T for transpose, norm() for the Frobenius norm, get_row_elements(), get_col_elements(), and get_flatten_elements().

Behavior notes

  • Only plain Python int and float values are accepted.
  • Division goes through zero_aware_division(). With the current default configuration, dividing by zero returns 0 instead of raising an exception.
  • The project is educational in scope and prioritizes clarity over performance.

Running tests

From a repository checkout:

python -m unittest discover -s tests

Repository examples

The 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_matrix

Repository layout

  • linear_algebra_toolkit/objects.py contains the Vector and Matrix implementations.
  • linear_algebra_toolkit/utils.py contains small shared helpers.
  • tests/ contains the unit tests for the public behavior.
  • examples/ contains runnable usage examples.

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

linear_algebra_toolkit-0.1.0.tar.gz (10.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

linear_algebra_toolkit-0.1.0-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file linear_algebra_toolkit-0.1.0.tar.gz.

File metadata

  • Download URL: linear_algebra_toolkit-0.1.0.tar.gz
  • Upload date:
  • Size: 10.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for linear_algebra_toolkit-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7e474ef6a7adfcfad2e6d97c7c531ac4921ef92b4dd29b66e5b3a772c6011270
MD5 89c10882e88f24d49ed625b9d6db193b
BLAKE2b-256 8fa7956b694f594fad24a2096a485dec88d5f803daa9034941d761a5c5e3f2e4

See more details on using hashes here.

File details

Details for the file linear_algebra_toolkit-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for linear_algebra_toolkit-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 903c9006b8c407ac6266605c893b9b9f52ef5ecec4df92ff1ccb5014e17a93e2
MD5 b3d06c6d704b03625bdd17e013c4190f
BLAKE2b-256 0fdff9904e4eea4f3853a1899236b7117275193738aec8a8fba588423853ae93

See more details on using hashes here.

Supported by

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