JavaScript

Tensorflow.js – tf.ceil()

Transformation in Machine Learning is the technique that scales the values to the nearest integer. To implement this task, Tensorflow.js provides the tf.ceil() function which scales the decimal value to the nearest ceil value.

Tf.ceil() Function

The tf.ceil() function in tensorflow.js returns the ceil values for the given decimal values in a tensor.

Syntax:

tf.ceil(tensor_input)

Parameter:

The tensor_input is a tensor that has numeric elements.
It can be one or two-dimensional.

Example 1:

Let’s create a one-dimensional tensor in js that has decimal values and apply the ceil() function.

<html>
<!--   CDN Link that delivers the Tensorflow.js framework -->
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs"></script>

<body>
<center><h1>Linux Hint</h1></center>
<center><h2>Tensorflow.js - tf.ceil() </h2></center>
<script>

let values = tf.tensor1d([8.56,3.45,7.89,8.32,9.03,1.00,45.6]);
//actual tensor
document.write("Actual Tensor: ",values);

document.write("<br>");
document.write("<br>");

//apply ceil() on the above tensor
document.write("Tensor with Ceil Values:- "+tf.ceil(values));
</script>

</body>
</html>

Output:

The ceil values were returned that are higher than the decimal values.

Example 2:

Let’s create a tensor that has two dimensions in js with 2 rows and 2 columns that has decimal values and get the ceil values.

<html>
<!--   CDN Link that delivers the Tensorflow.js framework -->
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs"></script>

<body>
<center><h1>Linux Hint</h1></center>
<center><h2>Tensorflow.js - tf.ceil() </h2></center>
<script>

let values = tf.tensor2d([[-34.4,4.56],[4.5,7.89]]);
//actual tensor
document.write("Actual Tensor: ",values);

document.write("<br>");
document.write("<br>");

//apply ceil() on the above tensor
document.write("Tensor with Ceil Values:- "+tf.ceil(values));
</script>

</body>
</html>

Output:

Example 3:

Let’s create a tensor that has two dimensions in js with 2 rows and 2 columns that has integer values and get the ceil/top values.

<html>
<!--   CDN Link that delivers the Tensorflow.js framework -->
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs"></script>

<body>
<center><h1>Linux Hint</h1></center>
<center><h2>Tensorflow.js - tf.ceil() </h2></center>
<script>

let values = tf.tensor2d([[-4,5],[8,-45]]);
//actual tensor
document.write("Actual Tensor: ",values);

document.write("<br>");
document.write("<br>");

//apply ceil() on the above tensor
document.write("Tensor with Ceil Values:- "+tf.ceil(values));
</script>

</body>
</html>

Output:

The ceil values were returned that are the same as the integer values.

Conclusion

In this Tensorflow.js tutorial, we learned how to get the ceil values using the tf.ceil() function with three different examples. The tf.ceil() function returns the top values that are higher than the given decimal values.

About the author

Gottumukkala Sravan Kumar

B tech-hon's in Information Technology; Known programming languages - Python, R , PHP MySQL; Published 500+ articles on computer science domain