# Is this the correct way?

Hi

Suppose we have a expression: z = x^2 *y + y, where x, y are both Tensors.

We want to calculate d(d z / d x) / dy. Here d is the partial derivative operator.

I do as follows:

``````import torch

x = torch.Tensor([3])
y = torch.Tensor([17])

loss = x**2 * y + y
loss.backward(create_graph=True, retain_graph=True)