向量相关计算

向量与向量的计算
x = torch.arange(4, dtype=torch.float32)
y = torch.ones(4, dtype=torch.float32) * 2
print(x)
print(y)

print(x + y)
print(x * y)
print(x / y)
print(x ** y)

print(y.dot(x))
print(torch.sum(x * y))

向量与矩阵
M = torch.arange(12, dtype=torch.float32).reshape(3, 4)
V = torch.arange(4, dtype=torch.float32) + 1print(M)
print(V)print(M + V)
print(M * V)
print(M / V)
print(M ** V)mv = torch.mv(M, V)
print(mv)

向量的范数
u = torch.tensor([3.0, -4.0])
print(torch.norm(u))
print(torch.abs(u).sum())

本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!