添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
曾经爱过的西装  ·  Kazuo KAWASAKI·  3 月前    · 
低调的警车  ·  VBA ...·  4 月前    · 
虚心的炒面  ·  Description of alert ...·  7 月前    · 
Community

Join the PyTorch developer community to contribute, learn, and get your questions answered.

Community Stories

Learn how our community solves real, everyday machine learning problems with PyTorch.

Developer Resources

Find resources and get questions answered

Events

Find events, webinars, and podcasts

Forums

A place to discuss PyTorch code, issues, install, research

Models (Beta)

Discover, publish, and reuse pre-trained models

torch. bernoulli ( input , * , generator = None , out = None ) Tensor

Draws binary random numbers (0 or 1) from a Bernoulli distribution.

The input tensor should be a tensor containing probabilities to be used for drawing the binary random number. Hence, all values in input have to be in the range: 0 input i 1 0 \leq \text{input}_i \leq 1

The i t h \text{i}^{th} element of the output tensor will draw a value 1 1 according to the i t h \text{i}^{th} probability value given in input .

out i B e r n o u l l i ( p = input i ) \text{out}_{i} \sim \mathrm{Bernoulli}(p = \text{input}_{i})
Parameters

input ( Tensor ) – the input tensor of probability values for the Bernoulli distribution

Keyword Arguments
  • generator ( torch.Generator , optional) – a pseudorandom number generator for sampling

  • out ( Tensor , optional ) – the output tensor.

  • Example:

    >>> a = torch.empty(3, 3).uniform_(0, 1)  # generate a uniform random matrix with range [0, 1]
    tensor([[ 0.1737,  0.0950,  0.3609],
            [ 0.7148,  0.0289,  0.2676],
            [ 0.9456,  0.8937,  0.7202]])
    >>> torch.bernoulli(a)
    tensor([[ 1.,  0.,  0.],
            [ 0.,  0.,  0.],
            [ 1.,  1.,  1.]])
    >>> a = torch.ones(3, 3) # probability of drawing "1" is 1
    >>> torch.bernoulli(a)
    tensor([[ 1.,  1.,  1.],
            [ 1.,  1.,  1.],
            [ 1.,  1.,  1.]])
    >>> a = torch.zeros(3, 3) # probability of drawing "1" is 0
    >>> torch.bernoulli(a)
    tensor([[ 0.,  0.,  0.],
            [ 0.,  0.,  0.],
            [ 0.,  0.,  0.]])
              For web site terms of use, trademark policy and other policies applicable to The PyTorch Foundation please see
              www.linuxfoundation.org/policies/. The PyTorch Foundation supports the PyTorch open source
              project, which has been established as PyTorch Project a Series of LF Projects, LLC. For policies applicable to the PyTorch Project a Series of LF Projects, LLC,
              please see www.lfprojects.org/policies/.