title: Best way to define a scalar using nn.Parameter in Pytorch
body: <p>In my CNN at some stage I want to multiply a feature map with some scalar which should be learnt by the network. Which of the following is the best way to do it or all are same? The scalar has to be initialised to 5.</p>
  <pre><code># Method 1
  def __init__(self):
      super(..., self).__init__()
      ...
      ...
      alpha = nn.Parameter(5)
      ...
  
  def forward(self, x):
      ...
      x = x * alpha
      return x
  </code></pre>
  <pre><code># Method 2
  def __init__(self):
      super(..., self).__init__()
      ...
      ...
      alpha = nn.Parameter(torch.tensor(5))
      ...
  
  def forward(self, x):
      ...
      x = x * alpha
      return x
  </code></pre>
  <pre><code># Method 3
  def __init__(self):
      super(..., self).__init__()
      ...
      ...
      alpha = nn.Parameter(torch.ones(1)*5)
      ...
  
  def forward(self, x):
      ...
      x = x * alpha
      return x
  </code></pre>
  <p>If all are same I would prefer Method 1 and let CNN learn the appropriate multiplier <code>alpha</code> for the feature map <code>x</code>. I hope in all cases alpha will be a float32 tensor initialised to 5. I am using PyTorch 1.3.1</p>
  <p>Yours sincerely,</p>
  <p>Mohit</p>