📜  Python – tensorflow.math.ceil()(1)

📅  最后修改于: 2023-12-03 14:46:07.716000             🧑  作者: Mango

Python - tensorflow.math.ceil()

The tensorflow.math.ceil() function is used to compute the ceiling of the input tensor element-wise. It rounds the value towards positive infinity.

Syntax
tensorflow.math.ceil(x, name=None)
Parameters
  • x (tensor): The input tensor.
  • name (str, optional): A name for the operation.
Return Value
  • A tensor with the same shape as x, where each element is rounded towards positive infinity.
Example
import tensorflow as tf

# Create input tensor
x = tf.constant([1.2, 2.7, -3.5, 4.8, -5.3])

# Compute ceiling
ceiling = tf.math.ceil(x)

# Print the result
print(ceiling)
Output
tf.Tensor([ 2.   3.  -3.   5.  -5.], shape=(5,), dtype=float32)

In the above example, we import the TensorFlow library and create an input tensor x with some floating-point values. We then use the tf.math.ceil() function to compute the ceiling of each element in the tensor x. Finally, we print the result, which gives us the tensor with each element rounded towards positive infinity.

It is important to note that the tf.math.ceil() function works element-wise, which means it operates independently on each element of the input tensor x. This allows us to apply the function to tensors of any shape.

Conclusion

The tensorflow.math.ceil() function is a useful tool when you need to round tensor elements towards positive infinity. It can be beneficial when dealing with numerical operations that require rounded values.