The size of tensor a (x) must match the size of tensor b (y) at non-singleton dimension z

Resin_Wu

关注

阅读 66

2022-06-28

问题描述

张量A和B在广播过程中,对应维度不匹配。

张量广播

PyTorch操作支持广播,其张量参数可以自动扩展为相同大小(不复制数据)。
PyTorch广播语义密切跟随numpy式广播。如果你熟悉数字广播,可以按照之前流程执行。
其广播机制遵循以下规则:

  1. 每个张量至少具有一个维度;
  2. 广播时,从尾部维度开始,满足尺寸大小相等或其中一个为1或其中一个不存在。

正例:
The size of tensor a (x) must match the size of tensor b (y) at non-singleton dimension z_广播机制

反例:
The size of tensor a (x) must match the size of tensor b (y) at non-singleton dimension z_正例_02

相关推荐

精彩评论(0)

0 0 举报