语法:
tf.broadcast_to(
input, shape, name=None
)
作用:利用广播将原始矩阵成倍增加,广播是使数组具有兼容形状以进行算术运算的过程。
如果对于每个尺寸对,两个形状是相等的或其中之一是一个,则两个形状是兼容的。
举个栗子:
>>>x = tf.constant([1, 2, 3])
>>>y = tf.broadcast_to(x, [3, 3])
>>>print(y)
tf.Tensor(
[[1 2 3]
[1 2 3]
[1 2 3]], shape=(3, 3), dtype=int32)
在这个栗子中,广播了具有[1,3]形状的输入Tensor,以输出具有[3,3]形状的Tensor。
参数详解
- input: 一个张量,广播的张量。
- shape: 一个张量, 必须是下列类型之一:int32,int64。一个一维的int张量, 期望输出的形状。
- name: 操作的名称(可选)。