Tensorflow.js is an open-source library developed by Google for running machine learning models and deep learning neural networks in the browser or node environment.
The tf.floorDiv() function is used to divide two Tensors element-wise and the returned result is rounded with floor function. It supports broadcasting.
Syntax:
tf.floorDiv (a, b)
Parameters: This function accepts two parameters which are illustrated below:
- a: The first input tensor as the numerator.
- b: The second input tensor as the denominator. It should, must have the same data type as “a”.
Return Value: It returns a Tensor for the rounded result of a/b, where a is the first Tensor and b is the second Tensor.
Example 1:
Javascript
// Importing the tensorflow.js library import * as tf from "@tensorflow/tfjs" // Initializing two Tensors const a = tf.tensor1d([2, 5, 14, 12]); const b = tf.tensor1d([1, 3, 4, 10]); // Calling the .floorDiv() function over the // above Tensors as its parameters a.floorDiv(b).print(); |
Output:
Tensor [2, 1, 3, 1]
Example 2:
Javascript
// Importing the tensorflow.js library import * as tf from "@tensorflow/tfjs" // Broadcasting div a with b const a = tf.tensor1d([3, 5, 15, 17]); const b = tf.scalar(2); // Calling the .floorDiv() function over the // above Tensors as its parameters a.floorDiv(b).print(); |
Output:
Tensor [1, 2, 7, 8]