pymc.distributions.shape_utils.broadcast_dist_samples_to#

pymc.distributions.shape_utils.broadcast_dist_samples_to(to_shape, samples, size=None)[source]#

Broadcast samples drawn from distributions to a given shape, taking into account the size (i.e. the number of samples) of the draw, which is prepended to the sample’s shape.

Parameters
to_shape: Tuple shape onto which the samples must be able to broadcast
samples: Iterable of ndarrays holding the sampled values
size: None, int or tuple (optional)

size of the sample set requested.

Returns
List of the broadcasted sample arrays

Examples

to_shape = (3, 1, 5)
size = 100
sample0 = np.random.randn(size)
sample1 = np.random.randn(size, 5)
sample2 = np.random.randn(size, 4, 5)
out = broadcast_dist_samples_to(
    to_shape,
    [sample0, sample1, sample2],
    size=size
)
assert np.all((o.shape == (size, 3, 4, 5) for o in out))
assert np.all(sample0[:, None, None, None] == out[0])
assert np.all(sample1[:, None, None] == out[1])
assert np.all(sample2[:, None] == out[2])
size = 100
to_shape = (3, 1, 5)
sample0 = np.random.randn(size)
sample1 = np.random.randn(5)
sample2 = np.random.randn(4, 5)
out = broadcast_dist_samples_to(
    to_shape,
    [sample0, sample1, sample2],
    size=size
)
assert np.all((o.shape == (size, 3, 4, 5) for o in out))
assert np.all(sample0[:, None, None, None] == out[0])
assert np.all(sample1 == out[1])
assert np.all(sample2 == out[2])