title: min-max normalization of a tensor in PyTorch
body: <p>I want to perform min-max normalization on a tensor in PyTorch.</p>
  <p>The formula to obtain min-max normalization is</p>
  <p><a href="https://i.stack.imgur.com/0YPfa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0YPfa.png" alt="enter image description here" /></a></p>
  <p>I want to perform min-max normalization on a tensor using some <code>new_min</code> and <code>new_max</code> <strong>without iterating through all elements</strong> of the tensor.</p>
  <pre><code>&gt;&gt;&gt;import torch
  &gt;&gt;&gt;x = torch.randn(5, 4)
  &gt;&gt;&gt;print(x)
  tensor([[-0.8785, -1.6898,  2.2129, -0.8375],
          [ 1.2927, -1.3187, -0.7087, -2.1143],
          [-0.6162,  0.6836, -1.3342, -0.7889],
          [-0.2934, -1.2526, -0.3265,  1.1933],
          [ 1.2494, -1.2130,  1.5959,  1.4232]])
  </code></pre>
  <p>Is there any way to min-max normalize the given tensor between two values <code>new_min, new_max</code>?</p>
  <p>Suppose I want to scale the tensor from <code>new_min = -0.25</code> to <code>new_max = 0.25</code></p>