# TensorFlow函数教程：tf.keras.backend.batch_dot

## tf.keras.backend.batch_dot函数

``````tf.keras.backend.batch_dot(
x,
y,
axes=None
)
``````

• x：ndim >= 2的Keras张量或变量。
• y：ndim >= 2的Keras张量或变量。
• axes：具有目标维度的（或单个）int列表。axes和axes的长度应该是相同的。

``````A tensor with shape equal to the concatenation of `x`'s shape
(less the dimension that was summed over) and `y`'s shape
(less the batch dimension and the dimension that was summed over).
If the final rank is 1, we reshape it to `(batch_size, 1)`.``````

``````Shape inference:
Let `x`'s shape be `(100, 20)` and `y`'s shape be `(100, 30, 20)`.
If `axes` is (1, 2), to find the output shape of resultant tensor,
loop through each dimension in `x`'s shape and `y`'s shape:

* `x.shape` : 100 : append to output shape
* `x.shape` : 20 : do not append to output shape,
dimension 1 of `x` has been summed over. (`dot_axes` = 1)
* `y.shape` : 100 : do not append to output shape,
always ignore first dimension of `y`
* `y.shape` : 30 : append to output shape
* `y.shape` : 20 : do not append to output shape,
dimension 2 of `y` has been summed over. (`dot_axes` = 2)
`output_shape` = `(100, 30)`
``````
``````    >>> x_batch = K.ones(shape=(32, 20, 1))
>>> y_batch = K.ones(shape=(32, 30, 20))
>>> xy_batch_dot = K.batch_dot(x_batch, y_batch, axes=[1, 2])
>>> K.int_shape(xy_batch_dot)
(32, 1, 30)``````

App下载  