[ 组合替代实现 ]torch.Tensor.bernoulli_¶
转写示例¶
p:输入概率,类型为 tensor 时¶
# PyTorch 写法
input.bernoulli_(p=x)
# Paddle 写法
paddle.assign(paddle.bernoulli(paddle.broadcast_to(x, input.shape)), input)
p:输入概率,类型为 float 时¶
# PyTorch 写法
input.bernoulli_(p=x)
# Paddle 写法
tensor = paddle.to_tensor([x])
paddle.assign(paddle.bernoulli(paddle.broadcast_to(tensor, input.shape)), input)