Skip to main content

GA Matrix

CI PyPI Python

GA Matrix provides small NumPy-backed matrix containers with label-based access, long-form pandas import/export helpers, and optional timestamp support for origin-destination data.

The PyPI distribution is named ga-matrix; the import package is named matrix.

Installation

python -m pip install ga-matrix

Development and test tools are available as extras:

python -m pip install -e ".[test]"
python -m pip install -e ".[dev]"

Quick Start

from matrix import MatrixOD

rows = ["A", "B"]
cols = ["X", "Y"]

od = MatrixOD(rows, cols, init={"A": {"X": 10}, "B": {"Y": 5}})
od["A", "Y"] = 3

assert od["A", "X"] == 10
assert od.sum() == 18

MatrixOD

MatrixOD stores a 2D origin-destination matrix. Rows and columns can be passed as label sequences or existing label-to-position mappings.

import pandas as pd

from matrix import MatrixOD

df = pd.DataFrame(
    [
        {"origin": "A", "destination": "X", "trips": 10},
        {"origin": "B", "destination": "Y", "trips": 5},
    ]
)

od = MatrixOD.read_df(
    rows=["A", "B"],
    cols=["X", "Y"],
    df=df,
    o_field="origin",
    d_field="destination",
    value_field="trips",
)

roundtrip = od.write_df(o_field="origin", d_field="destination", value_field="trips")

Supported operations are element-wise addition, subtraction, multiplication, and division with either a scalar or another matrix with the same labels.

scaled = od * 1.2
delta = scaled - od
col_totals = od.sum(axis=0)
row_totals = od.sum(axis=1)

MatrixODT

MatrixODT stores one MatrixOD per timestamp.

from matrix import MatrixODT

odt = MatrixODT(
    rows=["A", "B"],
    cols=["X", "Y"],
    timestamps=[0, 1],
    init={
        0: {"A": {"X": 10}},
        1: {"B": {"Y": 5}},
    },
)

assert odt["A", "X", 0] == 10
assert odt["A", "X", 99] == 0
assert odt.sum(axis=2)["A", "X"] == 10

MatrixODT.read_df() accepts a long-form DataFrame with origin, destination, timestamp, and value columns. If timestamps is omitted, timestamp labels are inferred from the DataFrame in first-seen order.

API Summary

  • MatrixOD(rows, cols, init=None, copy=False, mode=None)
  • MatrixOD.read_df(rows, cols, df, o_field="o", d_field="d", value_field="value")
  • MatrixOD.read_csv(rows, cols, file, ...)
  • MatrixOD.write_df(...)
  • MatrixOD.write_csv(file, ...)
  • MatrixODT(rows, cols, timestamps, init=None, copy=False, mode=None)
  • MatrixODT.read_df(rows, cols, timestamps=None, df=None, ...)
  • MatrixODT.read_csv(rows, cols, file, timestamps=None, ...)
  • MatrixODT.write_df(...)
  • MatrixODT.write_csv(file, ...)

Development

GA Matrix supports Python 3.10 and newer.

python -m pip install -e ".[dev]"
python -m compileall -q src
python -m pytest --cov=matrix --cov-report=term-missing
ruff check .
mypy
python -m pip check
python -m build
python -m twine check dist/*

Releases

src/matrix/_version.py is the only version source. To publish a release:

  1. Update __version__ in _version.py and commit the release changes.
  2. Push main and wait for CI to pass.
  3. Configure the PyPI Trusted Publisher with project ga-matrix, owner andreagemma, repository matrix, workflow release.yml, and environment pypi.
  4. Run the Create release GitHub Actions workflow. With no override it creates the v<version> tag, creates release notes, and dispatches the build and PyPI publication workflow.

PyPI versions are immutable. Increment _version.py before publishing different content.

License

GA Matrix is distributed under the MIT License. See LICENSE.

Release files for ga-matrix 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ga-matrix 0.1.2
File Size Uploaded
ga_matrix-0.1.2.tar.gz 14.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ga-matrix 0.1.2
File Interpreter ABI Platform
ga_matrix-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 26.6 kB

Release files / ga_matrix-0.1.2.tar.gz

Download URL ga_matrix-0.1.2.tar.gz
Size 14.1 kB
Tags Source
SHA-256 checksum
How to use checksums
39d771c0087991e54ec54ec2336dfa44f790d57109787d51984a229d96e43d28
BLAKE2b-256 checksum
How to use checksums
97ba67dafc1b7344db9a130ea2018b5600f6a8ce61846d13ac1d9a08c5c68e52
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 24, 2026.

Transparency log

Release files / ga_matrix-0.1.2-py3-none-any.whl

Download URL ga_matrix-0.1.2-py3-none-any.whl
Size 12.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9c765b9097147eb6703ea67ed375065039c7526251296a7e6d368a153e782e6e
BLAKE2b-256 checksum
How to use checksums
b8ee136d9c4a3f1b2371268dd20f70b282fbd53d56355f601f63b39aefb6a071
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 24, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page