Learn R Programming

torch (version 0.8.1)

torch_multinomial: Multinomial

Description

Multinomial

Usage

torch_multinomial(self, num_samples, replacement = FALSE, generator = NULL)

Arguments

self

(Tensor) the input tensor containing probabilities

num_samples

(int) number of samples to draw

replacement

(bool, optional) whether to draw with replacement or not

generator

(torch.Generator, optional) a pseudorandom number generator for sampling

multinomial(input, num_samples, replacement=False, *, generator=NULL, out=NULL) -> LongTensor

Returns a tensor where each row contains num_samples indices sampled from the multinomial probability distribution located in the corresponding row of tensor input.

Examples

Run this code
if (torch_is_installed()) {

weights = torch_tensor(c(0, 10, 3, 0), dtype=torch_float()) # create a tensor of weights
torch_multinomial(weights, 2)
torch_multinomial(weights, 4, replacement=TRUE)
}

Run the code above in your browser using DataLab