powered by
Multinomial
torch_multinomial(self, num_samples, replacement = FALSE, generator = NULL)
(Tensor) the input tensor containing probabilities
(int) number of samples to draw
(bool, optional) whether to draw with replacement or not
(torch.Generator, optional) a pseudorandom number generator for sampling
torch.Generator
Returns a tensor where each row contains num_samples indices sampled from the multinomial probability distribution located in the corresponding row of tensor input.
num_samples
input
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