How to calculate gradients on a tensor in PyTorch?
I want to calculate the gradient of a tensor and however, it gives error as 

RunTimeerror: grad can be implicitly created only for scalar outputs


and here is what I am trying to code:

x = torch.full((2,3), 4,requires_grad=True)
y = (2*x**2+3)
y.backward()


And at this point, it throws an error.

Since there is no summing up/reducing the loss-value , like .sum()
Hence the issue could be fixed by:

y.backward(torch.ones_like(x))


which performs a Jacobian-vector product with a tensor of all ones and get the gradient. 
