Files
Deep_Learning_M502019B/Lab1/code/1.3.py
2025-09-21 02:59:47 +00:00

13 lines
178 B
Python

import torch
x = torch.tensor(1.0, requires_grad=True)
y_1 = x**2
with torch.no_grad():
y_2 = x**3
y3 = y_1 + y_2
y3.backward()
print("梯度(dy_3/dx): ", x.grad.item())