Learn R Programming

torch (version 0.0.2)

torch_multinomial: Multinomial

Description

Multinomial

Arguments

input

(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

out

(Tensor, optional) the output tensor.

multinomial(input, num_samples, replacement=False, *, generator=None, out=None) -> 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
# NOT RUN {
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