Skip to content

DataMat API

DataMat extends pandas.DataFrame with matrix-oriented operations that retain labels. The section below is rendered from the live docstrings.

Bases: DataFrame

Matrix with labeled rows and columns supporting linear algebra semantics.

leverage cached property

Return leverage of matrix (diagonal of projection matrix).

DataMat([[1,2],[3,4],[5,6]],idxnames='i').leverage()

pinv cached property

Moore-Penrose pseudo-inverse.

vec property

Column-stacked vectorisation vec(M).

__getitem__(key)

X.getitem(k) == X[k]

X = DataMat([[1,2,3],[4,5,6]],colnames='cols',idxnames='rows') X[0].sum().squeeze()==5 True

__init__(*args, **kwargs)

Create a DataMat.

Inherit from :meth: pd.DataFrame.__init__.

Additional Parameters

idxnames (List of) name(s) for levels of index. colnames (List of) name(s) for levels of columns. name String naming DataMat object.

concat(other, axis=0, levelnames=False, toplevelname='v', suffixer='_', drop_vestigial_levels=False, **kwargs)

Concatenate self and other.

This uses the machinery of pandas.concat, but ensures that when two DataMats having multiindices with different number of levels are concatenated that new levels are added so as to preserve a result with a multiindex.

if other is a dictionary and levelnames is not False, then a new level in the multiindex is created naming the columns belonging to the original DataMats.

USAGE

a = DataVec([1,2],name='a',idxnames='i') b = DataMat([[1,2],[3,4]],name='b',idxnames='i',colnames='j') b.concat([a,b],axis=1,levelnames=True).columns.levels[0].tolist() ['b', 'a', 'b_0']

dg()

Return the diagonal vector diag(M) of a square matrix.

drop_vestigial_levels(axis=None)

Drop index & column levels that don't vary.

Takes a single optional parameter: - axis (default None): If axis=0, operate on index; if 1, on columns; if None, on both.

eig(hermitian=False, ascending=True)

Eigendecomposition. Returns eigenvalues & corresponding eigenvectors.

from_jax(wrapper) classmethod

Rebuild a :class:DataMat from a :class:DataMatJax wrapper.

matmul(other, strict=False, fillmiss=False)

Matrix product preserving labels on the surviving axes.

norm(ord=None, **kwargs)

Matrix norm ‖M‖_ord mirroring :func:numpy.linalg.norm.

proj(other)

Linear projection of self on other.

random(shape, distribution='normal', *, index=None, columns=None, idxnames=None, colnames=None, rng=None, name=None, **dist_kwargs) classmethod

Draw a random matrix with optional labelled axes.

Parameters

shape : tuple[int, int] Number of rows and columns. distribution : random-spec, default "normal" Name/tuple/callable describing the distribution. Supports the same shorthands as :meth:DataVec.random (normal, uniform, chi-square, exponential, Bernoulli, binomial, Poisson, etc.). index, columns : sequence or pandas.Index, optional Labels for rows/columns; defaults to simple RangeIndex. idxnames, colnames : str or sequence of str, optional Names applied to the index/column levels. rng : numpy.random.Generator | int | None, optional RNG or seed used by the draw. name : str, optional Matrix name. **dist_kwargs Additional keyword arguments forwarded to the distribution.

Returns

DataMat Labelled matrix of shape shape.

rank(**kwargs)

Matrix rank

resid(other)

Residual from projection of self on other.

set_index(columns, levels=None, inplace=False)

Set the DataMat index using existing columns.

X = DataMat([[1,2,3],[4,5,6]],columns=['a','b','c'],colnames='cols',idxnames='rows') X.set_index(['a','b'])

svd(hermitian=False)

Singular value composition into U@S.dg@V.T.

to_jax(*, dtype=float)

Convert the matrix into a JAX-compatible wrapper retaining labels.

tril(k=0)

Return lower triangular part as DataMat, preserving labels.

triu(k=0)

Return upper triangular part as DataMat, preserving labels.