megengine.random.RNG.poisson

RNG.poisson(lam, size=None)[源代码]

Random variable with poisson distribution \(\operatorname{Poisson}(\lambda)\).

The corresponding probability density function is

\[f(k ; \lambda)=\frac{\lambda^{k} e^{-\lambda}}{k !},\]

where k is the number of occurrences \(({\displaystyle k=0,1,2...})\).

参数
  • lam (Union[float, Tensor]) – the lambda parameter of the distribution. Must be non-negative.

  • size (Optional[Iterable[int]]) – the size of output tensor. If lam is a scalar and given size is, e.g., (m, n), then the output shape is (m, n). If lam is a Tensor with shape (k, v) and given size is, e.g., (m, n), then the output shape is (m, n, k, v). Default: None.

返回

the output tensor.

实际案例

import megengine as mge
import megengine.random as rand

x = rand.poisson(lam=2., size=(1, 3))
print(x.numpy())

lam = mge.Tensor([[1.,1.],
                [10,10]], dtype="float32")

x = rand.poisson(lam=lam)
print(x.numpy())

x = rand.poisson(lam=lam, size=(1,3))
print(x.numpy())

Outputs:

[[3. 1. 3.]]

[[ 2.  2.]
 [12. 11.]]

[[[[ 1.  1.]
   [11.  4.]]
  [[ 0.  0.]
   [ 9. 13.]]
  [[ 0.  1.]
   [ 7. 12.]]]]