Torch equivalent of numpy.random.choice?

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?

You can just sample in a 1D array and then reshape it to your desired size.

1 Like