solve¶
- xarray_einstats.linalg.solve(da, db, dims=None, **kwargs)[source]¶
Wrap
numpy.linalg.solve
.Usage examples of all arguments is available at the Intro to the linear algebra module page.
- Parameters:
- da, db
xarray.DataArray
- dimssequence of hashable, optional
It can have either length 2 or 3. If length 2, both dimensions should have the same length and be present in da, and only one of them should also be present in db. If length 3, the first two elements behave the same; the third element is a dimension of arbitrary length which can only present in db.
From NumPy’s docstring, a has
(..., M, M)
shape and b has(M,) or (..., M, K)
. Here, b can be(..., M)
this case is not limited to 1d, so dims with length two indicates the two dimensions of length M, with length 3 it is something like (M, M, K), which can be done thanks to named dimensions.- **kwargs
Passed to
xarray.apply_ufunc
- da, db
- Returns:
Examples
Dimension naming conventions are designed to ease inverse operation with
xarray.dot
.The following example illustrates what this means and how to check that solve worked correctly
import xarray as xr import numpy as np from xarray_einstats.linalg import solve from xarray_einstats.tutorial import generate_matrices_dataarray matrices = generate_matrices_dataarray() matrices
<xarray.DataArray (batch: 10, experiment: 3, dim: 4, dim2: 4)> Size: 4kB 0.0666 0.5816 0.6813 3.231 0.356 0.04923 ... 2.237 0.3365 0.6512 1.049 0.1507 Dimensions without coordinates: batch, experiment, dim, dim2
b = matrices.std("dim2") # dims (batch, experiment, dim) y2 = solve(matrices, b, dims=("dim", "dim2")) # dims (batch, experiment, dim2) np.allclose(b, xr.dot(matrices, y2, dims="dim2"))
True