lazymatrix.LazyMatrix
LazyMatrix for Python · 0.1.1
LazyMatrix(X: typing.Any, *, center: bool = True, scale: bool = True)An owned matrix with lazy column centering and scaling.
Parameters
X : numpy.ndarray or scipy.sparse matrix or array
Two-dimensional real numeric input. Sparse input must use CSR or CSC storage. Values are copied to float64 storage, and sparse copies are converted to canonical CSC. Later changes to X do not affect this object.
center : bool, default=True
Subtract each column's mean during matrix operations.
scale : bool, default=True
Divide each column by its population standard deviation. Exact zero scales are replaced with one.
Notes
Products and column access do not allocate a full normalized matrix. Dense input still requires a full raw-data copy. Multiple right-hand sides currently use repeated vector products. Nonfinite values follow the Rust core's IEEE arithmetic; missing values are not ignored.
Use toarray for explicit dense conversion and aslinearoperator for SciPy solvers. General slicing, mutation, elementwise arithmetic, and implicit NumPy conversion are unsupported.
Examples
>>> import numpy as np
>>> from lazymatrix import standardize
>>> Z = standardize(np.array([[1.0, 0.0], [3.0, 4.0]]))
>>> Z @ np.array([1.0, 2.0])
array([-3., 3.])
>>> Z[:, 0]
array([-1., 1.])__init__ {#init}
__init__(X: typing.Any, *, center: bool = True, scale: bool = True) -> Noneshape
shape(self) -> tuple[int, int]The logical number of rows and columns.
ndim
ndim(self) -> intThe number of dimensions, always two.
dtype
dtype(self) -> numpy.dtype[numpy.float64]The stored and output data type, always float64.
centers
centers(self) -> NDArray[np.float64] | NoneA copy of the original columns' fitted means, or None.
Transposing the matrix retains these original column parameters.
scales
scales(self) -> NDArray[np.float64] | NoneA copy of the original columns' fitted scales, or None.
Transposing the matrix retains these original column parameters.
T
T(self) -> "LazyMatrix"A transpose sharing the same raw storage and fitted parameters.
aslinearoperator
aslinearoperator() -> scipy.sparse.linalg.LinearOperatorExpose this matrix to SciPy's iterative linear algebra routines.
Returns
scipy.sparse.linalg.LinearOperator
An operator sharing this matrix's storage and supporting forward, transpose, and multiple-right-hand-side products.
Examples
>>> import numpy as np
>>> from scipy.sparse.linalg import lsqr
>>> from lazymatrix import standardize
>>> Z = standardize(np.array([[1.0], [3.0]]))
>>> lsqr(Z.aslinearoperator(), np.array([-2.0, 2.0]))[0]
array([2.])toarray
toarray() -> numpy.typing.NDArray[numpy.float64]Materialize the logical matrix as an independent dense array.
Returns
numpy.ndarray
A float64 array with this matrix's shape. This operation allocates storage for every logical entry, including normalized sparse zeros.

