# WeightedRandomSampler

Source: https://www.tensorplay.cn/docs/generated/tensorplay.utils.data.WeightedRandomSampler.html

# WeightedRandomSampler

class tensorplay.utils.data.WeightedRandomSampler(weights: [Sequence](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)[[float](https://docs.python.org/3/library/functions.html#float)], num_samples: [int](https://docs.python.org/3/library/functions.html#int), replacement: [bool](https://docs.python.org/3/library/functions.html#bool) = True, generator: [Generator](tensorplay.Generator.html#tensorplay.Generator) | [None](https://docs.python.org/3/library/constants.html#None) = None)[[source]](../_modules/tensorplay/utils/data.html#WeightedRandomSampler)

Samples elements from [0,..,len(weights)-1] with given probabilities (weights).

Parameters:

- weights ( sequence ) – a sequence of weights, not necessary summing up to one

- num_samples ([int](https://docs.python.org/3/library/functions.html#int)) – number of samples to draw

- replacement ([bool](https://docs.python.org/3/library/functions.html#bool)) – if True , samples are drawn with replacement. If not, they are drawn without replacement, which means that when a sample index is drawn for a row, it cannot be drawn again for that row.

- generator ([Generator](tensorplay.Generator.html#tensorplay.Generator)) – Generator used in sampling.
