pytorch tensor内所有元素相乘怎么实现
导读:本文共2532字符,通常情况下阅读需要8分钟。同时您也可以点击右侧朗读,来听本文内容。按键盘←(左) →(右) 方向键可以翻页。
摘要: tensor内所有元素相乘a=torch.Tensor([1,2,3])print(torch.prod(a))输出tensor(6.)tensor乘法运算汇总与解析元素一一相乘该操作又称作 “哈达玛积”, 简单来说就是 tensor 元素逐个相乘。这个操作,是通过 * 也就是常规的乘号操作符定义的操作结果。torch.mul 是等价的。importtorch... ...
目录
(为您整理了一些要点),点击可以直达。输出
tensor(6.)
该操作又称作 “哈达玛积”, 简单来说就是 tensor 元素逐个相乘。这个操作,是通过 * 也就是常规的乘号操作符定义的操作结果。torch.mul 是等价的。
这个操作是可以 broad cast 的。
torch.matmul: If both tensors are 1-dimensional, the dot product (scalar) is returned.
如果都是1维的,返回的就是 dot product 结果
torch.matmul: If both arguments are 2-dimensional, the matrix-matrix product is returned.
如果都是2维,那么就是矩阵乘法的结果返回。与 torch.mm 是等价的,torch.mm 仅仅能处理的是矩阵乘法。
torch.matmul: If the first argument is 1-dimensional and the second argument is 2-dimensional, a 1 is prepended to its dimension for the purpose of the matrix multiply. After the matrix multiply, the prepended dimension is removed.
如果第一个是 vector, 第二个是 matrix, 会在 vector 中增加一个维度。也就是 vector 变成了 与 matrix 相乘之后,变成 , 在结果中将 维 再去掉。
同样的道理, vector会被扩充一个维度。
上面的效果与 torch.bmm 是一样的。matmul 比 bmm 功能更加强大,但是 bmm 的语义非常明确, bmm 处理的只能是 3维的。
pytorch tensor内所有元素相乘怎么实现的详细内容,希望对您有所帮助,信息来源于网络。