Files
pytorch-study/04.ipynb
2025-06-12 00:14:11 +08:00

2.7 KiB

In [4]:
import torch
import numpy as np

torch.__version__
Out[4]:
'2.2.1'
In [11]:
a = torch.tensor(1)
b = a.item()
print(a)
print(b)
tensor(1)
1
In [13]:
a = [1, 2, 3]
b = torch.tensor(a)
c = b.numpy().tolist()
print(c)
[1, 2, 3]
In [18]:
a = torch.zeros(2, 3, 5)
print(a.shape)

print(a.size())

print(a.numel())
torch.Size([2, 3, 5])
torch.Size([2, 3, 5])
30
In [ ]:
x = torch.rand(2, 3, 5)
print(x.shape)