计算给定符号形状的广播的形状,
  • 1.广播的原则如果两个数组的后缘维度(trailing dimension,即从末尾开始算起的维度)的轴长度相符,

  • 2.或其中的一方的长度为1,则认为它们是广播兼容的。广播会在缺失和(或)长度为1的维度上进行。

张量的广播机制

import tensorflow as tf
shape_x = (6, 3)
shape_y = (5, 1, 3)
c=tf.broadcast_dynamic_shape(shape_x, shape_y)

print(c)
tf.Tensor([5 6 3], shape=(3,), dtype=int32)
import tensorflow as tf
shape_x = (6, 8)
shape_y = (5, 1, 3)
c=tf.broadcast_dynamic_shape(shape_x, shape_y)

print(c)
报错
InvalidArgumentError: Incompatible shapes: [6,8] vs. [5,1,3] [Op:BroadcastArgs]