MCPcopy Create free account
hub / github.com/dask/dask / sample

Function sample

dask/bag/random.py:12–37  ·  view source on GitHub ↗

Chooses k unique random elements from a bag. Returns a new bag containing elements from the population while leaving the original population unchanged. Parameters ---------- population: Bag Elements to sample. k: integer, optional Number of elements to sampl

(population, k, split_every=None)

Source from the content-addressed store, hash-verified

10
11
12def sample(population, k, split_every=None):
13 """Chooses k unique random elements from a bag.
14
15 Returns a new bag containing elements from the population while
16 leaving the original population unchanged.
17
18 Parameters
19 ----------
20 population: Bag
21 Elements to sample.
22 k: integer, optional
23 Number of elements to sample.
24 split_every: int (optional)
25 Group partitions into groups of this size while performing reduction.
26 Defaults to 8.
27
28 Examples
29 --------
30 >>> import dask.bag as db
31 >>> from dask.bag import random
32 >>> b = db.from_sequence(range(5), npartitions=2)
33 >>> list(random.sample(b, 3).compute()) # doctest: +SKIP
34 [1, 3, 5]
35 """
36 res = _sample(population=population, k=k, split_every=split_every)
37 return res.map_partitions(_finalize_sample, k)
38
39
40def choices(population, k=1, split_every=None):

Callers

nothing calls this directly

Calls 2

_sampleFunction · 0.85
map_partitionsMethod · 0.45

Tested by

no test coverage detected