A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://python.arviz.org/en/latest/getting_started/../api/generated/arviz.InferenceData.stack.html below:

arviz.InferenceData.stack — ArviZ dev documentation

arviz.InferenceData.stack#
InferenceData.stack(dimensions=None, groups=None, filter_groups=None, inplace=False, **kwargs)[source]#

Perform an xarray stacking on all groups.

Stack any number of existing dimensions into a single new dimension. Loops groups to perform Dataset.stack(key=value) for every kwarg if value is a dimension of the dataset. The selection is performed on all relevant groups (like posterior, prior, sample stats) while non relevant groups like observed data are omitted. See xarray.Dataset.stack()

Parameters:
dimensionsdict, optional

Names of new dimensions, and the existing dimensions that they replace.

groups: str or list of str, optional

Groups where the selection is to be applied. Can either be group names or metagroup names.

filter_groups{None, “like”, “regex”}, optional

If None (default), interpret groups as the real group or metagroup names. If “like”, interpret groups as substrings of the real group or metagroup names. If “regex”, interpret groups as regular expressions on the real group or metagroup names. A la pandas.filter.

inplacebool, optional

If True, modify the InferenceData object inplace, otherwise, return the modified copy.

kwargsdict, optional

It must be accepted by xarray.Dataset.stack().

Returns:
InferenceData

A new InferenceData object by default. When inplace==True perform selection in-place and return None

See also

xarray.Dataset.stack

Stack any number of existing dimensions into a single new dimension.

unstack

Perform an xarray unstacking on all groups of InferenceData object.

Examples

Use stack to stack any number of existing dimensions into a single new dimension. We first check the original object:

import arviz as az
idata = az.load_arviz_data("rugby")
idata

In order to stack two dimensions chain and draw to sample, we can use:

idata.stack(sample=["chain", "draw"], inplace=True)
idata

We can also take the example of custom InferenceData object and perform stacking. We first check the original object:

import numpy as np
datadict = {
    "a": np.random.randn(100),
    "b": np.random.randn(1, 100, 10),
    "c": np.random.randn(1, 100, 3, 4),
}
coords = {
    "c1": np.arange(3),
    "c99": np.arange(4),
    "b1": np.arange(10),
}
dims = {"c": ["c1", "c99"], "b": ["b1"]}
idata = az.from_dict(
    posterior=datadict, posterior_predictive=datadict, coords=coords, dims=dims
)
idata

In order to stack two dimensions c1 and c99 to z, we can use:

idata.stack(z=["c1", "c99"], inplace=True)
idata

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4