title: PyTorch: Is it possible to differentiate a matrix?
body: <p>How do you differentiate a matrix in PyTorch? I have tried the following but neither work:</p>
  <p>Instance 1:</p>
  <pre><code>a = torch.tensor([1., 2, 3], requires_grad=True)
  b = torch.tensor([4., 5, 6], requires_grad=True) 
  c = a*b
  c.backward()
  #print(b.grad)
  
  &gt;&gt;&gt; RuntimeError: grad can be implicitly created only for scalar outputs
  </code></pre>
  <p>Instance 2:</p>
  <pre><code>a = torch.tensor([1., 2, 3], requires_grad=True)
  b = torch.tensor([4., 5, 6], requires_grad=True)
  
  c = a*b
  print(b.grad)
  
  &gt;&gt;&gt; None
  </code></pre>