paddle. binomial ( count, prob, name=None ) [source]

Returns a tensor filled with random number from the Binomial Distribution, which supports Tensor shape broadcasting. The returned Tensor’s data type is int64.

\[out_i \sim Binomial (n = count_i, p = prob_i)\]
  • count (Tensor) – A tensor with each element specifying the size of a binomial distribution. The input data type should be int32 or int64.

  • prob (Tensor) – A tensor with each element specifying the probability of success in the binomial experiment. The input data type should be bfloat16, float16, float32, float64.

  • name (str, optional) – The default value is None. Normally there is no need for user to set this property. For more information, please refer to Name.


A Tensor filled with binomial random values with the same shape as the broadcasted Tensors of count and prob. The data type is int64.

Return type



>>> import paddle
>>> paddle.set_device('cpu')
>>> paddle.seed(100)

>>> n = paddle.to_tensor([10.0, 50.0])
>>> p = paddle.to_tensor([0.2, 0.6])
>>> out = paddle.binomial(n, p)
>>> print(out)
Tensor(shape=[2], dtype=int64, place=Place(cpu), stop_gradient=True,
[1 , 31])