Skip to main content

LazyMatrix for Python LazyMatrix logo

CI PyPI DOI

LazyMatrix centers and scales NumPy arrays and SciPy CSR and CSC matrices during matrix operations, without constructing a normalized copy. It supports matrix products, SciPy's iterative solvers, and an optional PyTorch first layer.

See the Python guide for supported operations and the API reference for public classes and methods.

Installation

Install lazymatrix from PyPI:

pip install lazymatrix

Python 3.11 or newer is required.

Usage

Fit column means and standard deviations, then multiply by the normalized matrix:

import numpy as np
from lazymatrix import standardize

X = np.array([[1.0, 0.0], [2.0, 3.0], [0.0, 4.0]])
Z = standardize(X)
prediction = Z @ np.array([1.0, -1.0])
gradient = Z.T @ prediction
column = Z[:, 0]

The operator owns a copy of the raw input and stores fitted column means and scales. Sparse inputs remain sparse and are stored in canonical CSC form. Stored values and results use float64. Standardization uses population standard deviations by default; pass df=1 for sample standard deviations.

Z.aslinearoperator() integrates with SciPy's iterative solvers. Call Z.toarray() to explicitly create a normalized dense array. Implicit dense conversion and elementwise NumPy operations are unsupported.

Normalization

Import LazyMatrix from lazymatrix for other normalization recipes. Use LazyMatrix(X, center="min", scale="range") for min-max scaling or LazyMatrix(X, center="median", scale="quantile_range") for median centering and interquartile-range scaling. Centering and scaling are independently optional, and exact zero scales become one.

Reuse training normalization without refitting with Z.normalization.transform(X_validation). The input must have the same features in the same order. See the normalization guide for all methods and fitted parameters for saving and restoring normalization.

PyTorch

Install the optional adapter for a neural network's first layer:

pip install "lazymatrix[torch]"

lazymatrix.torch.NormalizedLinear applies supplied centers and scales during training, with weights in normalized coordinates. It supports dense tensors and sparse COO and CSR tensors on CPU and CUDA. PyTorch 2.9 or newer is required. See the PyTorch guide for an example and supported dtypes.

Citation

If you use LazyMatrix in your research, please cite the release you used. See the citation guide for the Zenodo archive and citation metadata.

Contributing

From a repository checkout, run task python:check at the repository root to build, lint, and test the package. See the contribution guide for setup, packaging checks, and pull request guidance.

License

Licensed under either the Apache License, Version 2.0 or the MIT license, at your option.

Metadata

Release files for lazymatrix 0.4.0

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

Source distribution (sdist)

Source distribution for lazymatrix 0.4.0
File Size Uploaded Provenance Actions
lazymatrix-0.4.0.tar.gz 6.2 MB With provenance Details for lazymatrix-0.4.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for lazymatrix 0.4.0
File Actions
lazymatrix-0.4.0-cp311-abi3-win_amd64.whl CPython 3.11 abi3 Windows x86-64 Details for lazymatrix-0.4.0-cp311-abi3-win_amd64.whl
lazymatrix-0.4.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.11 abi3 Linux glibc 2.17+ x86-64 Details for lazymatrix-0.4.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
lazymatrix-0.4.0-cp311-abi3-macosx_11_0_arm64.whl CPython 3.11 abi3 macOS 11.0+ ARM64 Details for lazymatrix-0.4.0-cp311-abi3-macosx_11_0_arm64.whl
lazymatrix-0.4.0-cp311-abi3-macosx_10_12_x86_64.whl CPython 3.11 abi3 macOS 10.12+ x86-64 Details for lazymatrix-0.4.0-cp311-abi3-macosx_10_12_x86_64.whl

Total release size: 7.5 MB

Release files / lazymatrix-0.4.0.tar.gz

Download URL lazymatrix-0.4.0.tar.gz
Size 6.2 MB
Tags Source
SHA-256 checksum
How to use checksums
76c9eaada3a2d8cb0a154cfa30c748ae23c7e55fb7a70337eae9721b7f20724c
BLAKE2b-256 checksum
How to use checksums
c66f81812eb0e118748a9b0a8ed5759aa74cc81e4dbf1fc3b73ee835a7b313a6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 7, 2026.

Transparency log

Release files / lazymatrix-0.4.0-cp311-abi3-win_amd64.whl

Download URL lazymatrix-0.4.0-cp311-abi3-win_amd64.whl
Size 266.4 kB
Tags CPython 3.11 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
17ff434af511b0f09207f21a26290193a3cbce62ecac5688f79e7727a5a8d394
BLAKE2b-256 checksum
How to use checksums
6c652f55e966adec697e7b81013f9507694355cde7b6146248298e36a27bdc96
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 7, 2026.

Transparency log

Release files / lazymatrix-0.4.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL lazymatrix-0.4.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 367.6 kB
Tags CPython 3.11 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
b2ccd7479f92b1b2ef2c6589a39fff0bacfe885c604871cc2ea1311bbb8e5e24
BLAKE2b-256 checksum
How to use checksums
3ec7cee64c0c0f4a36a770660d2b81a3f631b696b80ed1863786e6c9073fcdf2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 7, 2026.

Transparency log

Release files / lazymatrix-0.4.0-cp311-abi3-macosx_11_0_arm64.whl

Download URL lazymatrix-0.4.0-cp311-abi3-macosx_11_0_arm64.whl
Size 328.1 kB
Tags CPython 3.11 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
62863f7ff0d0f9894231d9b2a5039e951087a3da7e81737a6ac2dfde7d0f25d6
BLAKE2b-256 checksum
How to use checksums
de7dd7cda1bdbff6f0b94dfb4b993efdce7347c6256c8c6c9b6d2bc0db274371
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 7, 2026.

Transparency log

Release files / lazymatrix-0.4.0-cp311-abi3-macosx_10_12_x86_64.whl

Download URL lazymatrix-0.4.0-cp311-abi3-macosx_10_12_x86_64.whl
Size 340.8 kB
Tags CPython 3.11 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
da5b5e1564ca70a27294e01f039c40f404e1951690082f8ac713f7deba95b05c
BLAKE2b-256 checksum
How to use checksums
807e6c5afa45d3a39e447e2988aaecf5adbf92db50d6a187ac0601f1fd7a9c35
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 7, 2026.

Transparency log

Security for lazymatrix 0.4.0

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.

Full provenance

All 5 files in this release have been uploaded with provenance metadata.

Select from 5 files

Attestation for lazymatrix-0.4.0.tar.gz

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 Nov 7, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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