arviz.concat#
- arviz.concat(*args, dim=None, copy=True, inplace=False, reset_dim=True)[source]#
Concatenate InferenceData objects.
Concatenates over
group
,chain
ordraw
. By default concatenates over unique groups. To concatenate overchain
ordraw
function needs identical groups and variables.The
variables
in thedata
-group are merged ifdim
are not found.- Parameters:
- *args
InferenceData
Variable length InferenceData list or Sequence of InferenceData.
- dim
str
, 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.
- *args
- Returns:
InferenceData
A new InferenceData object by default. When
inplace==True
merge args to first arg and returnNone
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 anInferenceData
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 anotherInferenceData
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 twoInferenceData
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.