import torch
x = torch.randint(10, 20, (3,4)) # [3,4]
y = torch.randint(0, 9, (2,4)) # [2,4]
print(x)
print(y)
z = x.unsqueeze(1) - y.unsqueeze(0) # p[3, 2, 4]
pytorch计算一个矩阵每一行分别与另一个矩阵的差值
最新推荐文章于 2025-01-13 17:25:32 发布
import torch
x = torch.randint(10, 20, (3,4)) # [3,4]
y = torch.randint(0, 9, (2,4)) # [2,4]
print(x)
print(y)
z = x.unsqueeze(1) - y.unsqueeze(0) # p[3, 2, 4]