arviz.concat#

arviz.concat(*args, dim=None, copy=True, inplace=False, reset_dim=True)[source]#

Concatenate InferenceData objects.

Concatenates over group, chain or draw. By default concatenates over unique groups. To concatenate over chain or draw function needs identical groups and variables.

The variables in the data -group are merged if dim are not found.

Parameters:
*argsInferenceData

Variable length InferenceData list or Sequence of InferenceData.

dimstr, optional

If defined, concatenated over the defined dimension. Dimension which is concatenated. If None, concatenates over unique groups.

copybool

If True, groups are copied to the new InferenceData object. Used only if dim is None.

inplacebool

If True, merge args to first object.

reset_dimbool

Valid only if dim is not None.

Returns:
InferenceData

A new InferenceData object by default. When inplace==True merge args to first arg and return None

See also

add_groups

Add new groups to InferenceData object.

extend

Extend InferenceData with groups from another InferenceData.

Examples

Use concat method to concatenate InferenceData objects. This will concatenates over unique groups by default. We first create an InferenceData object:

In [1]: import arviz as az
   ...: import numpy as np
   ...: data = {
   ...:     "a": np.random.normal(size=(4, 100, 3)),
   ...:     "b": np.random.normal(size=(4, 100)),
   ...: }
   ...: coords = {"a_dim": ["x", "y", "z"]}
   ...: dataA = az.from_dict(data, coords=coords, dims={"a": ["a_dim"]})
   ...: dataA
   ...: 
Out[1]: 
Inference data with groups:
	> posterior

We have created an InferenceData object with default group ‘posterior’. Now, we will create another InferenceData object:

In [2]: dataB = az.from_dict(prior=data, coords=coords, dims={"a": ["a_dim"]})
   ...: dataB
   ...: 
Out[2]: 
Inference data with groups:
	> prior

We have created another InferenceData object with group ‘prior’. Now, we will concatenate these two InferenceData objects:

In [3]: az.concat(dataA, dataB)
Out[3]: 
Inference data with groups:
	> posterior
	> prior

Now, we will concatenate over chain (or draw). It requires identical groups and variables. Here we are concatenating two identical InferenceData objects over dimension chain:

In [4]: az.concat(dataA, dataA, dim="chain")
Out[4]: 
Inference data with groups:
	> posterior

It will create an InferenceData with the original group ‘posterior’. In similar way, we can also concatenate over draws.