pytorch tensor内所有元素相乘怎么实现(pytorch,tensor,开发技术)

时间:2024-04-29 16:04:38 作者 : 石家庄SEO 分类 : 开发技术
  • TAG :

    pytorch%C2%A0tensor%E5%86%85%E6%89%80%E6%9C%89%E5%85%83%E7%B4%A0%E7%9B%B8%E4%B9%98%E6%80%8E%E4%B9%88%E5%AE%9E%E7%8E%B0

输出

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内所有元素相乘怎么实现的详细内容,希望对您有所帮助,信息来源于网络。
上一篇:微信小程序如何实现点餐小程序左侧滑动菜单下一篇:

5 人围观 / 0 条评论 ↓快速评论↓

(必须)

(必须,保密)

阿狸1 阿狸2 阿狸3 阿狸4 阿狸5 阿狸6 阿狸7 阿狸8 阿狸9 阿狸10 阿狸11 阿狸12 阿狸13 阿狸14 阿狸15 阿狸16 阿狸17 阿狸18