JavaScript

Tensorflkow.js – tf.floor()

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

Tf.floor() Function

The tf.floor() in Tensorflow.js returns the floor values for the given decimal values in a tensor.

Syntax:

tf.floor(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 floor() 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.floor() </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 floor() on the above tensor
document.write("Tensor with Floor Values:- "+tf.floor(values));
</script>

</body>
</html>

 
Output:


The floor values were returned that are lower to 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 floor 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.floor() </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 floor() on the above tensor
document.write("Tensor with Floor Values:- "+tf.floor(values));
</script>

</body>
</html>

 
Output:

The floor values were returned that are lower to the decimal values.

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 floor 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.floor() </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 floor() on the above tensor
document.write("Tensor with Floor Values:- "+tf.floor(values));
</script>

</body>
</html>

 
Output:


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

Conclusion

In this Tensorflow.js tutorial, we learned how to get the floor values using the tf.floor() function with three different examples. The tf.floor() function returns the floor values that are lower 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