YouTip LogoYouTip

Pytorch Torch Poisson

# PyTorch torch.poisson Function * * PyTorch torch Reference Manual](#) `torch.poisson` is a PyTorch function for generating random numbers from a Poisson distribution. ### Function Definition torch.poisson(lam, generator=None, out=None) ### Parameter Description * `lam` - The lambda parameter of the Poisson distribution (expectation/mean), must be non-negative * `generator` - Random number generator (optional) * `out` - Output tensor (optional) * * * ## Usage Examples ## Example import torch # Generate random tensor with single lambda value result1 = torch.poisson(lam=5.0, size=(3,3)) print("3x3 random tensor from Poisson distribution with lambda=5:") print(result1) # Use tensor as lambda parameter lam_tensor = torch.tensor([1.0,2.0,5.0,10.0]) result2 = torch.poisson(lam_tensor) print("nSampling results with tensor lambda:") print(result2) # Simulate count data lam = torch.tensor([0.5,1.0,2.0,5.0,10.0]) samples = torch.poisson(lam) print("nPoisson sampling with different lambda values:") for i,(l, s)in enumerate(zip(lam.tolist(), samples.tolist())): print(f" lambda={l}: {s}") * * PyTorch torch Reference Manual](#)
← Pytorch Torch PolygammaPytorch Torch Permute β†’