ExpandDims#

class bayesflow.adapters.transforms.ExpandDims(*, axis: int | tuple)[source]#

Bases: ElementwiseTransform

Expand the shape of an array.

Parameters:
axisint or tuple

The axis to expand.

Examples

shape (3,) array:

>>> a = np.array([1, 2, 3])

shape (2, 3) array:

>>> b = np.array([[1, 2, 3], [4, 5, 6]])
>>> dat = dict(a=a, b=b)
>>> ed = bf.adapters.transforms.ExpandDims("a", axis=0)
>>> new_dat = ed.forward(dat)
>>> new_dat["a"].shape
(1, 3)
>>> ed = bf.adapters.transforms.ExpandDims("a", axis=1)
>>> new_dat = ed.forward(dat)
>>> new_dat["a"].shape
(3, 1)
>>> ed = bf.adapters.transforms.ExpandDims("b", axis=1)
>>> new_dat = ed.forward(dat)
>>> new_dat["b"].shape
(2, 1, 3)

It is recommended to precede this transform with a bayesflow.adapters.transforms.ToArray transform.

classmethod from_config(config: dict, custom_objects=None) ExpandDims[source]#
get_config() dict[source]#
forward(data: ndarray, **kwargs) ndarray[source]#
inverse(data: ndarray, **kwargs) ndarray[source]#
__call__(data: ndarray, inverse: bool = False, **kwargs) ndarray#

Call self as a function.