Multiplies 2 tensors (and/or variables) and returns a *tensor*. 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 ten
(x, y)
| 1628 | |
| 1629 | @keras_export('keras.backend.dot') |
| 1630 | def dot(x, y): |
| 1631 | """Multiplies 2 tensors (and/or variables) and returns a *tensor*. |
| 1632 | |
| 1633 | When attempting to multiply a nD tensor |
| 1634 | with a nD tensor, it reproduces the Theano behavior. |
| 1635 | (e.g. `(2, 3) * (4, 3, 5) -> (2, 4, 5)`) |
| 1636 | |
| 1637 | Arguments: |
| 1638 | x: Tensor or variable. |
| 1639 | y: Tensor or variable. |
| 1640 | |
| 1641 | Returns: |
| 1642 | A tensor, dot product of `x` and `y`. |
| 1643 | |
| 1644 | Examples: |
| 1645 | ```python |
| 1646 | # dot product between tensors |
| 1647 | >>> x = K.placeholder(shape=(2, 3)) |
| 1648 | >>> y = K.placeholder(shape=(3, 4)) |
| 1649 | >>> xy = K.dot(x, y) |
| 1650 | >>> xy |
| 1651 | <tf.Tensor 'MatMul_9:0' shape=(2, 4) dtype=float32> |
| 1652 | ``` |
| 1653 | |
| 1654 | ```python |
| 1655 | # dot product between tensors |
| 1656 | >>> x = K.placeholder(shape=(32, 28, 3)) |
| 1657 | >>> y = K.placeholder(shape=(3, 4)) |
| 1658 | >>> xy = K.dot(x, y) |
| 1659 | >>> xy |
| 1660 | <tf.Tensor 'MatMul_9:0' shape=(32, 28, 4) dtype=float32> |
| 1661 | ``` |
| 1662 | |
| 1663 | ```python |
| 1664 | # Theano-like behavior example |
| 1665 | >>> x = K.random_uniform_variable(shape=(2, 3), low=0, high=1) |
| 1666 | >>> y = K.ones((4, 3, 5)) |
| 1667 | >>> xy = K.dot(x, y) |
| 1668 | >>> K.int_shape(xy) |
| 1669 | (2, 4, 5) |
| 1670 | ``` |
| 1671 | """ |
| 1672 | if ndim(x) is not None and (ndim(x) > 2 or ndim(y) > 2): |
| 1673 | x_shape = [] |
| 1674 | for i, s in zip(int_shape(x), array_ops.unstack(array_ops.shape(x))): |
| 1675 | if i is not None: |
| 1676 | x_shape.append(i) |
| 1677 | else: |
| 1678 | x_shape.append(s) |
| 1679 | x_shape = tuple(x_shape) |
| 1680 | y_shape = [] |
| 1681 | for i, s in zip(int_shape(y), array_ops.unstack(array_ops.shape(y))): |
| 1682 | if i is not None: |
| 1683 | y_shape.append(i) |
| 1684 | else: |
| 1685 | y_shape.append(s) |
| 1686 | y_shape = tuple(y_shape) |
| 1687 | y_permute_dim = list(range(ndim(y))) |
nothing calls this directly
no test coverage detected