fips.Matrix#
- class fips.Matrix(data, name=None, index=None, columns=None, dtype=None, copy=None, sparse=False)[source]#
Base class for all matrix-like objects in the inversion framework.
Wraps a pandas DataFrame and ensures consistent index handling. Matrices represent 2D components of the inversion problem, such as forward operators and covariance matrices.
- Parameters:
data (np.ndarray or pd.DataFrame or Matrix or scalar) – 2D data representing the matrix.
name (str, optional) – Name for the Matrix.
index (pd.MultiIndex) – Index for the rows of the DataFrame.
columns (pd.MultiIndex, optional) – Index for the columns of the DataFrame. If None, uses the same as index.
dtype (data type, optional) – Data type to force.
copy (bool, optional) – Whether to copy the data.
sparse (bool, default False) – If True, store the assembled matrix in pandas sparse format. Sparsification is applied after block assembly; use threshold zeroing in your builder before passing data here.
Attributes
blocksAccessor for retrieving MatrixBlock instances from the Matrix.
Return the columns of the underlying DataFrame.
Return the index of the underlying data.
True if the internal DataFrame uses pandas sparse storage.
Return the shape of the underlying data.
Return values as numpy array or sparse matrix.
The underlying data, which must be numeric and non-NaN.
Name of the structure, used for error messages and block naming.
Methods
copy([deep])Create a copy of the structure.
from_file(path)Load object from a pickle file.
reindex(index[, columns, verify_overlap, ...])Return a new instance with data reindexed to the specified index and columns.
round_index(decimals[, axis, inplace])Round float indices on the specified axis to given decimals.
scale(factor)Scale the matrix by a scalar factor.
to_dense()Return a copy with dense internal storage.
to_file(path)Save object to a pickle file.
to_frame()Get the underlying DataFrame data.
to_numpy()Get the underlying data as a NumPy array.
to_sparse([threshold])Return a copy with sparse internal storage.
to_xarray()Convert to xarray (not implemented for base Matrix class).
xs(key[, axis, level, drop_level])Cross-select data based on index/column values.