📅  最后修改于: 2023-12-03 15:19:04.032000             🧑  作者: Mango
tensorflow.math.truediv()
The tensorflow.math.truediv()
function is used to compute the true division of two tensors element-wise. It is a part of the TensorFlow math module and is commonly used in machine learning and deep learning applications.
tensorflow.math.truediv(x, y, name=None)
x
: A tensor of numeric type.y
: A tensor of numeric type.name
(optional): A name to give to the operation.A tensor with the same shape as the input tensors, containing the element-wise true division of x
by y
.
import tensorflow as tf
# Create input tensors
x = tf.constant([4, 8, 12], dtype=tf.float32)
y = tf.constant([2, 4, 6], dtype=tf.float32)
# Compute true division
result = tf.math.truediv(x, y)
# Print the result
print(result)
Output:
<tf.Tensor: shape=(3,), dtype=float32, numpy=array([2., 2., 2.], dtype=float32)>
In this example, we create two input tensors x
and y
with values [4, 8, 12]
and [2, 4, 6]
respectively. We then compute the true division of x
by y
using the tf.math.truediv()
function, which results in [2.0, 2.0, 2.0]
.