jax.random.choice#
- jax.random.choice(key, a, shape=(), replace=True, p=None, axis=0)[source]#
Generates a random sample from a given array.
Warning
If
p
has fewer non-zero elements than the requested number of samples, as specified inshape
, andreplace=False
, the output of this function is ill-defined. Please make sure to use appropriate inputs.- Parameters
key (
Union
[Array
,PRNGKeyArray
]) – a PRNG key used as the random key.a (
Union
[int
,Array
,ndarray
,bool_
,number
,bool
,float
,complex
]) – array or int. If an ndarray, a random sample is generated from its elements. If an int, the random sample is generated as if a were arange(a).shape (
Sequence
[int
]) – tuple of ints, optional. Output shape. If the given shape is, e.g.,(m, n)
, thenm * n
samples are drawn. Default is (), in which case a single value is returned.replace (
bool
) – boolean. Whether the sample is with or without replacement. default is True.p (
Union
[Array
,ndarray
,bool_
,number
,bool
,int
,float
,complex
,None
]) – 1-D array-like, The probabilities associated with each entry in a. If not given the sample assumes a uniform distribution over all entries in a.axis (
int
) – int, optional. The axis along which the selection is performed. The default, 0, selects by row.
- Return type
- Returns
An array of shape shape containing samples from a.