mindspore.ops.random_poisson
- mindspore.ops.random_poisson(shape, rate, seed=None, dtype=mstype.float32)[source]
Generates random numbers according to the Poisson random number distribution.
\[\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 mindspore.dtype.int32 or mindspore.dtype.int64.
rate (Tensor) – The μ parameter the distribution was constructed with. It represents the mean of the distribution and also the variance of the distribution. It should be a Tensor whose dtype is mindspore.dtype.int64, mindspore.dtype.int32, mindspore.dtype.float64, mindspore.dtype.float32 or mindspore.dtype.float16.
seed (int) – 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: mindspore.dtype.int64, mindspore.dtype.int32, mindspore.dtype.float64, mindspore.dtype.float32 or mindspore.dtype.float16. Default: mindspore.dtype.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 mindspore.dtype.int64 nor mindspore.dtype.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 [mindspore.dtype.int64, mindspore.dtype.int32, mindspore.dtype.float64, mindspore.dtype.float32 or mindspore.dtype.float16].
TypeError – If seed is not a non-negtive int.
TypeError – If dtype is not in [mindspore.dtype.int64, mindspore.dtype.int32, mindspore.dtype.float64, mindspore.dtype.float32 nor mindspore.dtype.float16].
ValueError – If any element of input shape tensor is not positive.
- Supported Platforms:
CPU
Examples
>>> from mindspore import Tensor, ops >>> import mindspore >>> # 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