Pytorch Added

This commit is contained in:
e2hang
2025-09-09 15:10:57 +08:00
parent a74884a555
commit a5fdeaf70e
20 changed files with 1307 additions and 2 deletions

View File

@@ -0,0 +1,24 @@
import numpy as np
import torch
a = np.array([1, 2, 3, 10, 9, 8, 7, 6, 5, 4])
b = torch.from_numpy(a)
print(b)
c = torch.arange(10)
print(c)
print(c.dtype, c.layout, c.device)
d = int(c.matmul(b))
#不写int是tensor(274)
e = c * b
print(d, e)
#in-place与广播
a1 = torch.tensor([1,1,3])
a2 = torch.tensor([1])#右对齐
a3 = torch.add(a1, a2)
print(a3, a3.layout)
#比较
print(torch.ge(a1, a2), torch.ne(a1, a2))