TensorFlow函数教程:tf.keras.backend.dot
2019-03-10 13:21 更新
tf.keras.backend.dot函数
tf.keras.backend.dot(
x,
y
)
定义在:tensorflow/python/keras/backend.py。
将2个张量(或变量)相乘并返回张量。
当试图将nD张量与nD张量相乘时,它会再现Theano行为。(例如:(2, 3) * (4, 3, 5) -> (2, 4, 5))
参数:
- x:张量或变量。
- y:张量或变量。
返回:
一个张量,x
和y
的点积。
例子:
# dot product between tensors
>>> x = K.placeholder(shape=(2, 3))
>>> y = K.placeholder(shape=(3, 4))
>>> xy = K.dot(x, y)
>>> xy
<tf.Tensor 'MatMul_9:0' shape=(2, 4) dtype=float32>
# dot product between tensors
>>> x = K.placeholder(shape=(32, 28, 3))
>>> y = K.placeholder(shape=(3, 4))
>>> xy = K.dot(x, y)
>>> xy
<tf.Tensor 'MatMul_9:0' shape=(32, 28, 4) dtype=float32>
# Theano-like behavior example
>>> x = K.random_uniform_variable(shape=(2, 3), low=0, high=1)
>>> y = K.ones((4, 3, 5))
>>> xy = K.dot(x, y)
>>> K.int_shape(xy)
(2, 4, 5)