prob140.Table.sample_from_dist¶
-
Table.
sample_from_dist
(n=1)¶ Randomly samples from the distribution.
Note that this function was previously named sample but was renamed due to naming conflicts with the datascience library.
Parameters: - n : int
Number of times to sample from the distribution (default: 1)
Returns: - float or array
Samples from the distribution
Examples
>>> dist = Table().with_columns( ... 'Value', make_array(2, 3, 4), ... 'Probability', make_array(0.25, 0.5, 0.25)) >>> dist.sample_from_dist() 3 >>> dist.sample_from_dist() 2 >>> dist.sample_from_dist(10) array([3, 2, 2, 4, 3, 4, 3, 4, 3, 3])