tf.keras.backend.dot
Stay organized with collections
Save and categorize content based on your preferences.
Multiplies 2 tensors (and/or variables) and returns a tensor.
tf.keras.backend.dot(
x, y
)
When attempting to multiply a nD tensor
with a nD tensor, it reproduces the Theano behavior.
(e.g. (2, 3) * (4, 3, 5) -> (2, 4, 5)
)
Arguments |
x
|
Tensor or variable.
|
y
|
Tensor or variable.
|
Returns |
A tensor, dot product of x and y .
|
Examples:
# 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)
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2020-10-01 UTC.
[null,null,["Last updated 2020-10-01 UTC."],[],[],null,["# tf.keras.backend.dot\n\n\u003cbr /\u003e\n\n|---------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------|\n| [TensorFlow 2 version](/api_docs/python/tf/keras/backend/dot) | [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/python/keras/backend.py#L1629-L1698) |\n\nMultiplies 2 tensors (and/or variables) and returns a *tensor*.\n\n#### View aliases\n\n\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.keras.backend.dot`](/api_docs/python/tf/keras/backend/dot), \\`tf.compat.v2.keras.backend.dot\\`\n\n\u003cbr /\u003e\n\n tf.keras.backend.dot(\n x, y\n )\n\nWhen attempting to multiply a nD tensor\nwith a nD tensor, it reproduces the Theano behavior.\n(e.g. `(2, 3) * (4, 3, 5) -\u003e (2, 4, 5)`)\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Arguments --------- ||\n|-----|---------------------|\n| `x` | Tensor or variable. |\n| `y` | Tensor or variable. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A tensor, dot product of `x` and `y`. ||\n\n\u003cbr /\u003e\n\n#### Examples:\n\n # dot product between tensors\n \u003e\u003e\u003e x = K.placeholder(shape=(2, 3))\n \u003e\u003e\u003e y = K.placeholder(shape=(3, 4))\n \u003e\u003e\u003e xy = K.dot(x, y)\n \u003e\u003e\u003e xy\n \u003ctf.Tensor 'MatMul_9:0' shape=(2, 4) dtype=float32\u003e\n\n # dot product between tensors\n \u003e\u003e\u003e x = K.placeholder(shape=(32, 28, 3))\n \u003e\u003e\u003e y = K.placeholder(shape=(3, 4))\n \u003e\u003e\u003e xy = K.dot(x, y)\n \u003e\u003e\u003e xy\n \u003ctf.Tensor 'MatMul_9:0' shape=(32, 28, 4) dtype=float32\u003e\n\n # Theano-like behavior example\n \u003e\u003e\u003e x = K.random_uniform_variable(shape=(2, 3), low=0, high=1)\n \u003e\u003e\u003e y = K.ones((4, 3, 5))\n \u003e\u003e\u003e xy = K.dot(x, y)\n \u003e\u003e\u003e K.int_shape(xy)\n (2, 4, 5)"]]