Updated 3 years ago
import torch
a=torch.rand(5,6)
a
tensor([[0.5419, 0.3143, 0.6584, 0.9437, 0.9633, 0.1524],
[0.1854, 0.4016, 0.9758, 0.7905, 0.0589, 0.7849],
[0.4571, 0.0459, 0.8982, 0.8369, 0.7827, 0.4306],
[0.4899, 0.9846, 0.3701, 0.1365, 0.7703, 0.4230],
[0.0916, 0.3859, 0.9431, 0.6487, 0.7634, 0.9500]])
b=torch.tensor([[[4.,3]]])
print(b.shape)
print(b.dtype)
torch.Size([1, 1, 2])
torch.float32
x=torch.tensor(4.)
y=torch.tensor(3., requires_grad=True)
z=torch.tensor(5., requires_grad=True)
deri=y**2-1+z*y
deri.backward()
print(x.grad)
print(y.grad)
None
tensor(11.)