Torch equivalent of numpy.random.choice? - PyTorch Forums
https://discuss.pytorch.org/t/torch-equivalent-of-numpy-random-choice/...01.03.2022 · Torch equivalent of numpy.random.choice? Forceless (Forceless) March 1, 2022, 7:41am #21. Hi, Both randperm and multinomial cannot solve my problem cause they cannot generate multi-dimension tensor. In numpy: sample_set = [0.4,0.2,0.1] np.random.sample (sample_set,shape= [3,3,3,3],p= [0.33,0.33,0.34]) Is there any equivalent method in torch ...
torch.rand — PyTorch 1.11.0 documentation
pytorch.org › docs › stabletorch.rand(*size, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) → Tensor. Returns a tensor filled with random numbers from a uniform distribution on the interval. [ 0, 1) [0, 1) [0,1) The shape of the tensor is defined by the variable argument size. Parameters.
Random Choice with Pytorch?
thetopsites.net › article › 59461811as the other mentioned, torch does not have choice you can use randint or permutation instead import torch n = 4 choices = torch.rand(4, 3) choices_flat = choices.view(-1) index = torch.randint(choices_flat.numel(), (n,)) # or if replace = False index = torch.randperm(choices_flat.numel())[:n] select = choices_flat[index]