arviz.concat#
- arviz.concat(*args, dim=None, copy=True, inplace=False, reset_dim=True)[source]#
Concatenate InferenceData objects.
Concatenates over
group,chainordraw. By default concatenates over unique groups. To concatenate overchainordrawfunction needs identical groups and variables.The
variablesin thedata-group are merged ifdimare 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
dimis None.- inplacebool
If True, merge args to first object.
- reset_dimbool
Valid only if dim is not None.
- *args
- Returns:
InferenceDataA new InferenceData object by default. When
inplace==Truemerge args to first arg and returnNone
See also
add_groupsAdd new groups to InferenceData object.
extendExtend InferenceData with groups from another InferenceData.
Examples
Use
concatmethod to concatenate InferenceData objects. This will concatenates over unique groups by default. We first create anInferenceDataobject: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
InferenceDataobject with default group ‘posterior’. Now, we will create anotherInferenceDataobject: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
InferenceDataobject with group ‘prior’. Now, we will concatenate these twoInferenceDataobjects: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
InferenceDataobjects over dimension chain:In [4]: az.concat(dataA, dataA, dim="chain") Out[4]: Inference data with groups: > posterior
It will create an
InferenceDatawith the original group ‘posterior’. In similar way, we can also concatenate over draws.