nvidia.dali.fn.random.choice#

nvidia.dali.fn.random.choice(__a, __shape_like=None, /, *, bytes_per_sample_hint=[0], p=None, preserve=False, seed=-1, shape=None, device=None, name=None)#

Generates a random sample from a given 1D array.

The probability of selecting a sample from the input is determined by the corresponding probability specified in p argument.

The shape of the generated data can be either specified explicitly with a shape argument, or chosen to match the shape of the __shape_like input, if provided. If none are present, a single value per sample is generated.

The type of the output matches the type of the input. For scalar inputs, only integral types are supported, otherwise any type can be used. The operator supports selection from an input containing elements of one of DALI enum types, that is: nvidia.dali.types.DALIDataType(), nvidia.dali.types.DALIImageType(), or nvidia.dali.types.DALIInterpType().

Supported backends
  • ‘cpu’

Parameters:
  • __a (scalar or TensorList) – If a scalar value __a is provided, the operator behaves as if [0, 1, ..., __a-1] list was passed as input. Otherwise __a is treated as 1D array of input samples.

  • __shape_like (TensorList, optional) – Shape of this input will be used to infer the shape of the output, if provided.

Keyword Arguments:
  • bytes_per_sample_hint (int or list of int, optional, default = [0]) –

    Output size hint, in bytes per sample.

    If specified, the operator’s outputs residing in GPU or page-locked host memory will be preallocated to accommodate a batch of samples of this size.

  • p (float or list of float or TensorList of float, optional) – Distribution of the probabilities. If not specified, uniform distribution is assumed.

  • preserve (bool, optional, default = False) – Prevents the operator from being removed from the graph even if its outputs are not used.

  • seed (int, optional, default = -1) –

    Random seed.

    If not provided, it will be populated based on the global seed of the pipeline.

  • shape (int or list of int or TensorList of int, optional) – Shape of the output data.