Random Sampling (cupy.random)

Differences between cupy.random and numpy.random:

  • CuPy provides Legacy Random Generation API (see also: NumPy 1.16 Reference). The new random generator API (numpy.random.Generator class) introduced in NumPy 1.17 has not been implemented yet.

  • Most functions under cupy.random support the dtype option, which do not exist in the corresponding NumPy APIs. This option enables generation of float32 values directly without any space overhead.

  • CuPy does not guarantee that the same number generator is used across major versions. This means that numbers generated by cupy.random by new major version may not be the same as the previous one, even if the same seed and distribution are used.

Simple random data

cupy.random.rand

Returns an array of uniform random values over the interval [0, 1).

cupy.random.randn

Returns an array of standard normal random values.

cupy.random.randint

Returns a scalar or an array of integer values over [low, high).

cupy.random.random_integers

Return a scalar or an array of integer values over [low, high]

cupy.random.random_sample

Returns an array of random values over the interval [0, 1).

cupy.random.random

Returns an array of random values over the interval [0, 1).

cupy.random.ranf

Returns an array of random values over the interval [0, 1).

cupy.random.sample

Returns an array of random values over the interval [0, 1).

cupy.random.choice

Returns an array of random values from a given 1-D array.

cupy.random.bytes

Returns random bytes.

Permutations

cupy.random.shuffle

Shuffles an array.

cupy.random.permutation

Returns a permuted range or a permutation of an array.

Distributions

cupy.random.beta

Beta distribution.

cupy.random.binomial

Binomial distribution.

cupy.random.chisquare

Chi-square distribution.

cupy.random.dirichlet

Dirichlet distribution.

cupy.random.exponential

Exponential distribution.

cupy.random.f

F distribution.

cupy.random.gamma

Gamma distribution.

cupy.random.geometric

Geometric distribution.

cupy.random.gumbel

Returns an array of samples drawn from a Gumbel distribution.

cupy.random.hypergeometric

hypergeometric distribution.

cupy.random.laplace

Laplace distribution.

cupy.random.logistic

Logistic distribution.

cupy.random.lognormal

Returns an array of samples drawn from a log normal distribution.

cupy.random.logseries

Log series distribution.

cupy.random.multinomial

Returns an array from multinomial distribution.

cupy.random.multivariate_normal

Multivariate normal distribution.

cupy.random.negative_binomial

Negative binomial distribution.

cupy.random.noncentral_chisquare

Noncentral chisquare distribution.

cupy.random.noncentral_f

Noncentral F distribution.

cupy.random.normal

Returns an array of normally distributed samples.

cupy.random.pareto

Pareto II or Lomax distribution.

cupy.random.poisson

Poisson distribution.

cupy.random.power

Power distribution.

cupy.random.rayleigh

Rayleigh distribution.

cupy.random.standard_cauchy

Standard cauchy distribution.

cupy.random.standard_exponential

Standard exponential distribution.

cupy.random.standard_gamma

Standard gamma distribution.

cupy.random.standard_normal

Returns an array of samples drawn from the standard normal distribution.

cupy.random.standard_t

Standard Student’s t distribution.

cupy.random.triangular

Triangular distribution.

cupy.random.uniform

Returns an array of uniformly-distributed samples over an interval.

cupy.random.vonmises

von Mises distribution.

cupy.random.wald

Wald distribution.

cupy.random.weibull

weibull distribution.

cupy.random.zipf

Zipf distribution.

Random generator

cupy.random.RandomState

Portable container of a pseudo-random number generator.

cupy.random.seed

Resets the state of the random number generator with a seed.

cupy.random.get_random_state

Gets the state of the random number generator for the current device.

cupy.random.set_random_state

Sets the state of the random number generator for the current device.

Note

CuPy does not provide cupy.random.get_state nor cupy.random.set_state at this time. Use cupy.random.get_random_state() and cupy.random.set_random_state() instead. Note that these functions use cupy.random.RandomState instance to represent the internal state, which cannot be serialized.