ArviZ Base

1.0.0 · active · verified Thu Apr 16

arviz-base is a Python package that provides core ArviZ features and converters, serving as a fundamental component of the modular ArviZ 1.0 ecosystem. It focuses on data structures, primarily leveraging `xarray.DataTree`, and conversion utilities from various probabilistic programming languages (PPLs). This library, currently at version 1.0.0, is under active development as part of the broader ArviZ refactoring, aiming for increased flexibility and a minimal dependency footprint.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates loading an example dataset using `load_arviz_data` and then extracting data with `extract`. It also shows how to convert raw Python dictionaries containing NumPy arrays into an ArviZ-compatible `xarray.DataTree` using `from_dict`.

import arviz_base as az
import numpy as np

# Load an example dataset provided by ArviZ Base
idata = az.load_arviz_data("centered_eight")
print(f"Loaded DataTree with groups: {list(idata.keys())}")

# Extract a specific group, e.g., 'posterior', combining chain and draw dimensions
extracted_data = az.extract(idata, group="posterior")
print(f"\nExtracted posterior data shape: {extracted_data.sizes}")

# Convert a simple dictionary to a DataTree
my_data = {
    "posterior": {
        "alpha": np.random.normal(0, 1, size=(4, 500)),
        "beta": np.random.normal(0, 0.5, size=(4, 500))
    }
}
custom_idata = az.from_dict(my_data)
print(f"\nCustom DataTree with groups: {list(custom_idata.keys())}")

view raw JSON →