fips.Operator#
- class fips.Operator(data, rows, cols, name=None)[source]#
A matrix with a
Spaceof labels on each axis.The matrix is kept in its cheapest form (
data, one of the forms offips.linalg): a dense array, a SciPy sparse matrix, a diagonal, Kronecker factors. Its rows are labeled byrowsand its columns bycols, in the order of each space. Products, sums and selections check the labels: two operators combine only when the spaces they meet on have the same labels, in any order (an exact join).An operator is not changed in place: every method returns a new one. NumPy defers to it (
__array_ufunc__ = None), sonp.float64(2) * opis an operator andarray + opraises, asop + arraydoes.- Parameters:
data (LinearOperator | sp.spmatrix | sp.sparray | npt.ArrayLike) – The matrix, with rows in the order of rows and columns in the order of cols. An array or a sparse matrix is copied, and the copy is read-only: changing data afterwards leaves the operator as it was. A sparse matrix stays sparse (a diagonal one becomes a
DiagonalOperator); a form offips.linalgalready holds its own copy and is kept as it is. A DataFrame is refused, since its labels would be ignored: usefrom_frame(). So is anOperator: usealign()to put it on other labels, or itsdatafor the matrix by position.rows (
Space) – The labels of the rows.cols (
Space) – The labels of the columns.name (
str|None) – What the matrix is (“forward”, “prior_cov”, …). A name that is not a string is converted to one.
- Raises:
TypeError – If data is a pandas object or an
Operator, or rows or cols is not a Space.ValueError – If the shape of data does not match the spaces, or it stores a NaN.
See also
Operator.from_frameAn operator from a labeled DataFrame.
Operator.from_blocksAn operator from its blocks.
fips.CovarianceA symmetric operator on one space.
Examples
>>> import numpy as np >>> import pandas as pd >>> from fips import Operator, Space, Vector >>> state = Space({"flux": pd.Index(["a", "b"], name="cell")}) >>> obs = Space({"co2": pd.Index([1, 2, 3], name="obs_id")}) >>> H = Operator(np.array([[1.0, 0.0], [0.0, 1.0], [1.0, 1.0]]), obs, state) >>> H.shape (3, 2) >>> x = Vector([2.0, 3.0], state) >>> (H @ x).values array([2., 3., 5.])
Attributes
The labels of the columns. |
|
The matrix, in its form (a |
|
a string, or None. |
|
The labels of the rows. |
|
The number of rows and of columns. |
|
the columns become the rows, labels and all. |
Methods
|
Return the operator on rows and cols, which must have exactly its labels. |
|
Return the matrix as a new dense array, rows and columns in the spaces' order. |
|
Build an operator from its blocks, each named by its row and its column block. |
|
Build an operator from a DataFrame, reading its labels. |
|
Return the operator with its float labels rounded ( |
|
Return the matrix as a new SciPy CSR array, rows and columns in the spaces' order. |
|
Return the matrix as a dense DataFrame. |