【发布时间】:2021-11-20 20:41:37
【问题描述】:
我在探索PyTorch,看不懂下面例子的输出:
# Initialize x, y and z to values 4, -3 and 5
x = torch.tensor(4., requires_grad = True)
y = torch.tensor(-3., requires_grad = True)
z = torch.tensor(5., requires_grad = True)
# Set q to sum of x and y, set f to product of q with z
q = x + y
f = q * z
# Compute the derivatives
f.backward()
# Print the gradients
print("Gradient of x is: " + str(x.grad))
print("Gradient of y is: " + str(y.grad))
print("Gradient of z is: " + str(z.grad))
输出
Gradient of x is: tensor(5.)
Gradient of y is: tensor(5.)
Gradient of z is: tensor(1.)
我毫不怀疑我的困惑源于一个小小的误解。有人可以逐步解释吗?
【问题讨论】:
标签: python deep-learning neural-network pytorch backpropagation