mindspore.ops.random_poisson

mindspore.ops.random_poisson(shape, rate, seed=None, dtype=mstype.float32)[source]

Generates random number Tensor with shape shape according to a Poisson distribution with mean rate.

\[\text{P}(i|μ) = \frac{\exp(-μ)μ^{i}}{i!}\]
Parameters
  • shape (Tensor) – The shape of random tensor to be sampled from each poisson distribution, 1-D Tensor whose dtype is mstype.int32 or mstype.int64.

  • rate (Tensor) – The \(μ\) parameter the distribution is constructed with. It represents the mean of the distribution and also the variance of the distribution. It should be a Tensor whose dtype is mstype.int64, mstype.int32, mstype.float64, mstype.float32 or mstype.float16.

  • seed (int, optional) – Seed is used as entropy source for the random number engines to generate pseudo-random numbers and must be non-negative. Default: None , which will be treated as 0.

  • dtype (mindspore.dtype) – The data type of output: mstype.int64, mstype.int32, mstype.float64, mstype.float32 or mstype.float16. Default: mstype.float32.

Returns

A Tensor whose shape is mindspore.concat(['shape', mindspore.shape('rate')], axis=0) and data type is equal to argument dtype.

Raises
  • TypeError – If shape is not a Tensor.

  • TypeError – If datatype of shape is not mstype.int64 nor mstype.int32.

  • ValueError – If shape of shape is not 1-D.

  • TypeError – If rate is not a Tensor nor a scalar.

  • TypeError – If datatype of rate is not in [mstype.int64, mstype.int32, mstype.float64, mstype.float32 or mstype.float16].

  • TypeError – If seed is not a non-negtive int.

  • TypeError – If dtype is not in [mstype.int64, mstype.int32, mstype.float64, mstype.float32 nor mstype.float16].

  • ValueError – If any element of input shape tensor is not positive.

Supported Platforms:

GPU CPU

Examples

>>> import mindspore
>>> import numpy as np
>>> from mindspore import Tensor, ops
>>> # case 1: 1-D shape, 2-D rate, float64 output
>>> shape = Tensor(np.array([2, 2]), mindspore.int64)
>>> rate = Tensor(np.array([[5.0, 10.0], [5.0, 1.0]]), mindspore.float32)
>>> output = ops.random_poisson(shape, rate, seed=5, dtype=mindspore.float64)
>>> print(output.shape, output.dtype)
(2, 2, 2, 2) Float64
>>> # case 2: 1-D shape, scalar rate, int64 output
>>> shape = Tensor(np.array([2, 2]), mindspore.int64)
>>> rate = Tensor(5.0, mindspore.float64)
>>> output = ops.random_poisson(shape, rate, seed=5, dtype=mindspore.int64)
>>> print(output.shape, output.dtype)
(2, 2) Int64