MCPcopy Create free account
hub / github.com/catboost/catboost / reservoir_sampling

Function reservoir_sampling

library/python/reservoir_sampling/__init__.py:4–16  ·  view source on GitHub ↗
(data, nsamples, prng=None)

Source from the content-addressed store, hash-verified

2
3
4def reservoir_sampling(data, nsamples, prng=None):
5 if prng is None:
6 prng = random
7
8 result = []
9 for i, entry in enumerate(data):
10 if i < nsamples:
11 result.append(entry)
12 else:
13 j = prng.randint(0, i)
14 if j < nsamples:
15 result[j] = entry
16 return result

Callers 1

recover_core_dump_fileFunction · 0.90

Calls 1

appendMethod · 0.45

Tested by

no test coverage detected