import torch from torch.distributions import Normal dist = Normal(0, 1) prob = dist.cdf(1) print(prob)
import torch from torch.distributions import Normal dist = Normal(-1, 2) samples = dist.sample((5,)) print(samples)Output: tensor([-0.9065, -1.6891, -0.0537, -2.2369, -0.7642]) In both examples, we use the torch.distributions package to create a Normal distribution with a specified mean and standard deviation. The first example computes the probability of a random variable being less than or equal to a given value (1 in this case) using the cdf method. The second example generates a sample of random numbers from the Normal distribution using the sample method. The torch.distributions package is a part of the PyTorch library.