tf.math.multiply
Stay organized with collections
Save and categorize content based on your preferences.
Returns an element-wise x * y.
tf.math.multiply(
x, y, name=None
)
Used in the notebooks
Used in the guide |
Used in the tutorials |
|
|
For example:
x = tf.constant(([1, 2, 3, 4]))
tf.math.multiply(x, x)
<tf.Tensor: shape=(4,), dtype=..., numpy=array([ 1, 4, 9, 16], dtype=int32)>
Since tf.math.multiply
will convert its arguments to Tensor
s, you can also
pass in non-Tensor
arguments:
tf.math.multiply(7,6)
<tf.Tensor: shape=(), dtype=int32, numpy=42>
If x.shape
is not the same as y.shape
, they will be broadcast to a
compatible shape. (More about broadcasting
here.)
For example:
x = tf.ones([1, 2]);
y = tf.ones([2, 1]);
x * y # Taking advantage of operator overriding
<tf.Tensor: shape=(2, 2), dtype=float32, numpy=
array([[1., 1.],
[1., 1.]], dtype=float32)>
The reduction version of this elementwise operation is tf.math.reduce_prod
Args |
x
|
A Tensor. Must be one of the following types: bfloat16 ,
half , float32 , float64 , uint8 , int8 , uint16 ,
int16 , int32 , int64 , complex64 , complex128 .
|
y
|
A Tensor . Must have the same type as x .
|
name
|
A name for the operation (optional).
|
A Tensor
. Has the same type as x
.
Raises |
- InvalidArgumentError: When
x and y have incompatible shapes or types.
|
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. Some content is licensed under the numpy license.
Last updated 2024-04-26 UTC.
[null,null,["Last updated 2024-04-26 UTC."],[],[],null,["# tf.math.multiply\n\n\u003cbr /\u003e\n\n|----------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.16.1/tensorflow/python/ops/math_ops.py#L475-L524) |\n\nReturns an element-wise x \\* y.\n\n#### View aliases\n\n\n**Main aliases**\n\n[`tf.multiply`](https://www.tensorflow.org/api_docs/python/tf/math/multiply)\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.multiply`](https://www.tensorflow.org/api_docs/python/tf/math/multiply)\n\n\u003cbr /\u003e\n\n tf.math.multiply(\n x, y, name=None\n )\n\n### Used in the notebooks\n\n| Used in the guide | Used in the tutorials |\n|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| - [Introduction to Tensors](https://www.tensorflow.org/guide/tensor) - [Migrate the SavedModel workflow](https://www.tensorflow.org/guide/migrate/saved_model) - [Training \\& evaluation with the built-in methods](https://www.tensorflow.org/guide/keras/training_with_built_in_methods) | - [Customization basics: tensors and operations](https://www.tensorflow.org/tutorials/customization/basics) - [Parametrized Quantum Circuits for Reinforcement Learning](https://www.tensorflow.org/quantum/tutorials/quantum_reinforcement_learning) - [Universal Sentence Encoder](https://www.tensorflow.org/hub/tutorials/semantic_similarity_with_tf_hub_universal_encoder) - [Universal Sentence Encoder-Lite demo](https://www.tensorflow.org/hub/tutorials/semantic_similarity_with_tf_hub_universal_encoder_lite) - [TFX Estimator Component Tutorial](https://www.tensorflow.org/tfx/tutorials/tfx/components) |\n\n#### For example:\n\n x = tf.constant(([1, 2, 3, 4]))\n tf.math.multiply(x, x)\n \u003ctf.Tensor: shape=(4,), dtype=..., numpy=array([ 1, 4, 9, 16], dtype=int32)\u003e\n\nSince [`tf.math.multiply`](../../tf/math/multiply) will convert its arguments to `Tensor`s, you can also\npass in non-`Tensor` arguments: \n\n tf.math.multiply(7,6)\n \u003ctf.Tensor: shape=(), dtype=int32, numpy=42\u003e\n\nIf `x.shape` is not the same as `y.shape`, they will be broadcast to a\ncompatible shape. (More about broadcasting\n[here](https://docs.scipy.org/doc/numpy/user/basics.broadcasting.html).)\n\n#### For example:\n\n x = tf.ones([1, 2]);\n y = tf.ones([2, 1]);\n x * y # Taking advantage of operator overriding\n \u003ctf.Tensor: shape=(2, 2), dtype=float32, numpy=\n array([[1., 1.],\n [1., 1.]], dtype=float32)\u003e\n\nThe reduction version of this elementwise operation is [`tf.math.reduce_prod`](../../tf/math/reduce_prod)\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|--------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `x` | A Tensor. Must be one of the following types: `bfloat16`, `half`, `float32`, `float64`, `uint8`, `int8`, `uint16`, `int16`, `int32`, `int64`, `complex64`, `complex128`. |\n| `y` | A `Tensor`. Must have the same type as `x`. |\n| `name` | A name for the operation (optional). |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n\n\u003cbr /\u003e\n\nA `Tensor`. Has the same type as `x`.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|---|---|\n| \u003cbr /\u003e - InvalidArgumentError: When `x` and `y` have incompatible shapes or types. ||\n\n\u003cbr /\u003e"]]