Random

Collection of random Ivy functions

ivy.multinomial(probs, num_samples, f=None)[source]

Draws samples from a multinomial distribution. Specifcally, returns a tensor where each row contains num_samples indices sampled from the multinomial probability distribution located in the corresponding row of tensor input.

Parameters
  • probs (array) – The unnormalized probabilities for all classes [batch_shape, num_classes]

  • num_samples (int) – Number of independent samples to draw for each row slice

  • f (ml_framework, optional) – Machine learning framework. Inferred from inputs if None.

Returns

Drawn samples from the multinomial distribution.

ivy.randint(low, high, shape, dev_str='cpu', f=None)[source]

Returns a tensor filled with random integers generated uniformly between low (inclusive) and high (exclusive).

Parameters
  • low (int) – Lowest integer to be drawn from the distribution.

  • high (int) – One above the highest integer to be drawn from the distribution.

  • shape (tuple) – a tuple defining the shape of the output tensor.

  • dev_str (str) – device on which to create the array ‘cuda:0’, ‘cuda:1’, ‘cpu’ etc.

  • f (ml_framework, optional) – Machine learning framework. Inferred from inputs if None.

Returns

ivy.random_uniform(low=0.0, high=1.0, shape=None, dev_str='cpu', f=None)[source]

Draws samples from a uniform distribution. Samples are uniformly distributed over the half-open interval [low, high) (includes low, but excludes high). In other words, any value within the given interval is equally likely to be drawn by uniform.

Parameters
  • low (float) – Lower boundary of the output interval. All values generated will be greater than or equal to low. The default value is 0.

  • high (float) – Upper boundary of the output interval. All values generated will be less than high. The default value is 1.0.

  • shape – Output shape. If the given shape is, e.g., (m, n, k), then m * n * k samples are drawn. If size is None (default), a single value is returned.

  • dev_str (str) – device on which to create the array ‘cuda:0’, ‘cuda:1’, ‘cpu’ etc.

  • f (ml_framework, optional) – Machine learning framework. Inferred from inputs if None.

Returns

Drawn samples from the parameterized uniform distribution.

ivy.seed(seed_value=0, f=None)[source]

Sets the seed for random number generation.

Parameters
  • seed_value (int) – Seed for random number generation, must be a positive integer.

  • f (ml_framework, optional) – Machine learning framework. Inferred from inputs if None.

ivy.shuffle(x, f=None)[source]

Shuffles the given array along axis 0.

Parameters
  • x (array) – An array object, in the specific Machine learning framework.

  • f (ml_framework, optional) – Machine learning framework. Inferred from inputs if None.

Returns

An array object, shuffled along the first dimension.