larzmatrix
Small-matrix linear algebra in pure Python. No numpy, zero dependencies.
A Matrix type with the operations you need for small systems: arithmetic,
transpose, determinant, inverse, and solving Ax = b by Gaussian elimination with
partial pivoting. For a handful of dimensions - transforms, geometry, least
squares, teaching - this is all you need, and it installs anywhere.
from larzmatrix import Matrix
A = Matrix([[2, 1], [1, 3]])
A.determinant() # 5.0
A.inverse()
A.solve([3, 5]) # x such that A x = [3, 5]
A * Matrix([[1, 0], [0, 1]]) # matrix product
A.T # transpose
Why
- No heavyweight dependency. numpy is wonderful and enormous; when you just need to invert a 3x3 or solve a small system, larzmatrix is a few hundred readable lines and zero install cost.
- The core operations, correct. Determinant, inverse (Gauss-Jordan), and
solveall use partial pivoting for numerical stability, and singular matrices raise instead of returning nonsense. - Clean API.
+ - *(scalar and matrix),.T,.trace(),.identity(n), tolerant==.
Install
pip install larzmatrix
Usage
from larzmatrix import Matrix
Matrix.identity(3)
Matrix([[1, 2], [3, 4]]) * Matrix([[5, 6], [7, 8]]) # [[19, 22], [43, 50]]
Matrix([[1, 2], [3, 4]]).determinant() # -2.0
Matrix([[4, 7], [2, 6]]).inverse()
Matrix([[2, 1], [1, 3]]).solve([5, 10]) # [1.0, 3.0]
Tests
python -m unittest discover -s tests -v # 19 tests incl. det/inverse/solve
The Larz stack
One of 30+ pure-Python, zero-dependency libraries at github.com/larz-scripter - pairs with larzstats.
License
MIT (c) larz-scripter
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file larzmatrix-0.1.0.tar.gz.
File metadata
- Download URL: larzmatrix-0.1.0.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
be77aee63be4b54fbd66502f791470873552114ac306fbd1e5ecabcfafca6154
|
|
| MD5 |
95b3e7623a20c3fddee5671e2264a62e
|
|
| BLAKE2b-256 |
e4e8971c8214f64d9513e834aab62ac8fc9ed2acba533389284f201f7ae2386b
|
File details
Details for the file larzmatrix-0.1.0-py3-none-any.whl.
File metadata
- Download URL: larzmatrix-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
50ab1d83ca73cef5b623ca7f000394eba14b3d558388ec88b9ab8b35ba8c334d
|
|
| MD5 |
676929d901bbfa9a07857a7f83a3d613
|
|
| BLAKE2b-256 |
e436ebda7a1b772f57a75d79ca7d6338baeab6ffaa6a6effc98b43f27ca78084
|