我正在研究PyTorch
官方docs的教程。我正在尝试了解内容。从You can do many crazy things with autograd!
x = torch.randn(3, requires_grad=True)
y = x * 2
i = 0
while y.data.norm() < 100:
y = y * 2
i+= 1
print(x)
print(y)
print(i)
输出:
tensor([-0.6933, 0.1126, 0.3913], requires_grad=True)
tensor([-88.7455, 14.4082, 50.0871], grad_fn=<MulBackward>)
6
在点x
上找到w.r.t到[0.1, 1.0, 0.0001]
gradients = torch.tensor([0.1, 1.0, 0.0001], dtype=torch.float)
y.backward(gradients)
print(x.grad)
输出:
tensor([ 12.8000, 128.0000, 0.0128])
据我了解,i
等于6
。然后y = (2x)^7
和导数与PyTorch
不同。替换值时,它以7
为因数
到我的衍生物。
PyTorch
的答案只是用x
的给定点替换dy/dx = 2^7 * x
问题:
如何导出导数?
参考:
答案 0 :(得分:1)
如果仔细观察一下表达式,就会发现y = x * (2^7)
的派生词是2^7 * x
。