Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PyTorch torch.poisson function

PyTorch torch.poisson function


PyTorch torch reference manual PyTorch torch reference manual

torch.poisson is a function in PyTorch used to generate random numbers from a Poisson distribution.

Function definition

torch.poisson(lam, generator=None, out=None)

Parameter Description


Usage examples

Example

import

torch

Generate a random tensor using a single lambda value

result1

=

torch.

poisson

(

lam

=

5.0

,

size

=

(

3

,

3

)

)

print

(

"3x3 random tensor from a Poisson distribution with lambda=5:"

)

print

(

result1

)

Use a tensor as the lambda parameter

lam_tensor

=

torch.

tensor

(

[

1.0

,

2.0

,

5.0

,

10.0

]

)

result2

=

torch.

poisson

(

lam_tensor

)

print

(

"nSampling result using a 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 reference manual