title: The output of numerical calculation of BCEWithLogitsLoss for PyTorch example
body: <p>When I looked the example code of BCEWithLogitsLoss in PyTorch Docs. I am confusing about the output result of loss function and formula.</p>
  
  <p><a href="https://pytorch.org/docs/stable/nn.html" rel="nofollow noreferrer">PyTorch Example</a>:</p>
  
  <pre><code>&gt;&gt;&gt; loss = nn.BCEWithLogitsLoss()
  &gt;&gt;&gt; input = torch.randn(3, requires_grad=True)
  &gt;&gt;&gt; target = torch.empty(3).random_(2)
  &gt;&gt;&gt; output = loss(input, target)
  &gt;&gt;&gt; output.backward()
  
  input : tensor([0.4764, -2.4063,  0.1563], requires_grad=True)
  target: tensor([0., 1., 1.])
  output: tensor(1.3567, grad_fn=&lt;BinaryCrossEntropyWithLogitsBackward&gt;)
  </code></pre>
  
  <p>But according to the formula by showing:</p>
  
  <p><a href="https://i.stack.imgur.com/4dApG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4dApG.png" alt="enter image description here"></a></p>
  
  <p>The output of loss function should have shape (3,) instead of single value ,since the shape of input and output both are (3,) . I was thinking that the output may was the sum of Ln or else, but still no idea. Could someone help me to explain that?</p>
  
  <p>As @Dishin H Goyani reminded that the default reduction is 'mean'. I did a simple test.</p>
  
  <pre><code>&gt;&gt;&gt; target_n = target.numpy()
  &gt;&gt;&gt; input_n  = input.detach().numpy()
  &gt;&gt;&gt; def sigmoid(array):return 1/(1+np.exp(-array))
  &gt;&gt;&gt; output_n = -1*(target_n*np.log(sigmoid(input_n))+(1-target_n)*np.log(1-sigmoid(input_n)))
  output_n : array([0.95947516, 2.4926252 , 0.61806685], dtype=float32)
  &gt;&gt;&gt; np.mean(output_n)
  1.3567224
  </code></pre>
  
  <p>The result is matched.</p>
  
  <p>As you seen, the default Wn is 1.</p>