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, and release workflows.

License

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

Metadata

Release files for lazymatrix 0.3.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.3.0
File Size Uploaded Provenance Actions
lazymatrix-0.3.0.tar.gz 6.2 MB With provenance Details for lazymatrix-0.3.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for lazymatrix 0.3.0
File Actions
lazymatrix-0.3.0-cp311-abi3-win_amd64.whl CPython 3.11 abi3 Windows x86-64 Details for lazymatrix-0.3.0-cp311-abi3-win_amd64.whl
lazymatrix-0.3.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.3.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
lazymatrix-0.3.0-cp311-abi3-macosx_11_0_arm64.whl CPython 3.11 abi3 macOS 11.0+ ARM64 Details for lazymatrix-0.3.0-cp311-abi3-macosx_11_0_arm64.whl
lazymatrix-0.3.0-cp311-abi3-macosx_10_12_x86_64.whl CPython 3.11 abi3 macOS 10.12+ x86-64 Details for lazymatrix-0.3.0-cp311-abi3-macosx_10_12_x86_64.whl

Total release size: 7.5 MB

Release files / lazymatrix-0.3.0.tar.gz

Download URL lazymatrix-0.3.0.tar.gz
Size 6.2 MB
Tags Source
SHA-256 checksum
How to use checksums
cff16d4836192ff1e7487cbd39d6ab605d5f0ffff8552f7ec98bb04037381ed2
BLAKE2b-256 checksum
How to use checksums
31de339cdffcf5b60166d1c58cfd811bf35e44c6d6f1da52ebc8bd9c23087d24
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 5, 2026.

Transparency log

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

Download URL lazymatrix-0.3.0-cp311-abi3-win_amd64.whl
Size 266.0 kB
Tags CPython 3.11 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
66122ff9f5f956d6599c82e8a01af987b5aebc669069941b3e406024e6445348
BLAKE2b-256 checksum
How to use checksums
84b4d4fdf1c82f8602f24ad89201aa5ffa625ae3353e008d4b29bb8ded2e464c
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 5, 2026.

Transparency log

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

Download URL lazymatrix-0.3.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 367.0 kB
Tags CPython 3.11 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
64d13232e7aafe01a1544ebe70c71b174c3e52a7a0347ee7e88a9bf9faee7133
BLAKE2b-256 checksum
How to use checksums
0d904291497052c065dd0c3c63097ede488f97ff095c8e2ec1392de7b4fbfbec
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 5, 2026.

Transparency log

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

Download URL lazymatrix-0.3.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
50aacd1ed5fa51e87270907a861cb0e598ae3764c6d93047bb7d8e2f226f9f60
BLAKE2b-256 checksum
How to use checksums
bc1f17cb615c3440bd0aaef92ef565e42f2794ffad516a1804279175ecc87198
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 5, 2026.

Transparency log

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

Download URL lazymatrix-0.3.0-cp311-abi3-macosx_10_12_x86_64.whl
Size 340.4 kB
Tags CPython 3.11 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
e36c7f1016082954440f86f0faea0b6c1a975e105fcdd937c8f4d3b0d8c0bfb5
BLAKE2b-256 checksum
How to use checksums
83dcff89a69d26312c76c6c705cad76dd2dc0298c9a069b1b4953d216af2b56c
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 5, 2026.

Transparency log

Security for lazymatrix 0.3.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.3.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 5, 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