[英]PyTorch derivative has no degree
我正在研究PyTorch
官方文檔中的教程。 我正在嘗試了解內容。 從開始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
在[0.1, 1.0, 0.0001]
點找到x
的導數wrt
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
題:
如何導出導數?
參考文獻:
如果仔細看一下表達式,就會發現y = x * (2^7)
,其導數是2^7 * x
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.