choice(self, a, size=None, replace=True, p=None, chunks='auto')
This docstring was copied from numpy.random.mtrand.RandomState.choice.
Some inconsistencies with the Dask version may exist.
New code should use the choice
method of a default_rng()
instance instead; please see the :None:ref:`random-quick-start`
.
Setting user-specified probabilities through p
uses a more general but less efficient sampler than the default. The general sampler produces a different sample than the optimized sampler even if each element of p
is 1 / len(a).
Sampling random rows from a 2-D array is not possible with this function, but is possible with :None:None:`Generator.choice`
through its axis
keyword.
If an ndarray, a random sample is generated from its elements. If an int, the random sample is generated as if it were np.arange(a)
Output shape. If the given shape is, e.g., (m, n, k)
, then m * n * k
samples are drawn. Default is None, in which case a single value is returned.
Whether the sample is with or without replacement. Default is True, meaning that a value of a
can be selected multiple times.
The probabilities associated with each entry in a. If not given, the sample assumes a uniform distribution over all entries in a
.
If a is an int and less than zero, if a or p are not 1-dimensional, if a is an array-like of size 0, if p is not a vector of probabilities, if a and p have different lengths, or if replace=False and the sample size is greater than the population size
The generated random samples
Generates a random sample from a given 1-D array
Generator.choice
which should be used in new code
Generate a uniform random sample from np.arange(5) of size 3:
This example is valid syntax, but we were not able to check execution>>> np.random.choice(5, 3) # doctest: +SKIP array([0, 3, 4]) # randomThis example is valid syntax, but we were not able to check execution
>>> #This is equivalent to np.random.randint(0,5,3)
Generate a non-uniform random sample from np.arange(5) of size 3:
This example is valid syntax, but we were not able to check execution>>> np.random.choice(5, 3, p=[0.1, 0, 0.3, 0.6, 0]) # doctest: +SKIP array([3, 3, 0]) # random
Generate a uniform random sample from np.arange(5) of size 3 without replacement:
This example is valid syntax, but we were not able to check execution>>> np.random.choice(5, 3, replace=False) # doctest: +SKIP array([3,1,0]) # randomThis example is valid syntax, but we were not able to check execution
>>> #This is equivalent to np.random.permutation(np.arange(5))[:3]
Generate a non-uniform random sample from np.arange(5) of size 3 without replacement:
This example is valid syntax, but we were not able to check execution>>> np.random.choice(5, 3, replace=False, p=[0.1, 0, 0.3, 0.6, 0]) # doctest: +SKIP array([2, 3, 0]) # random
Any of the above can be repeated with an arbitrary array-like instead of just integers. For instance:
This example is valid syntax, but we were not able to check execution>>> aa_milne_arr = ['pooh', 'rabbit', 'piglet', 'Christopher'] # doctest: +SKIPSee :
... np.random.choice(aa_milne_arr, 5, p=[0.5, 0.1, 0.1, 0.3]) # doctest: +SKIP array(['pooh', 'pooh', 'pooh', 'Christopher', 'piglet'], # random dtype='<U11')
Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.
Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)
SVG is more flexible but power hungry; and does not scale well to 50 + nodes.
All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them