Thursday, October 16, 2025
HomeLanguagesJavascriptTensorflow.js tf.div() Function

Tensorflow.js tf.div() Function

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.div() function is used to divides the two specified Tensors element-wise. It supports broadcasting.

Syntax:

tf.div (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 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([3, 5, 10, 15]);
const b = tf.tensor1d([2, 5, 2, 7]);
 
// Calling the .div() function over the
// above Tensors as its parameters
a.div(b).print();


Output:

Tensor
   [1.5, 1, 5, 2.1428571]

Example 2:

Javascript




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
 
// Broadcasting the div a with b
const a = tf.tensor1d([1, 12, 17, 20]);
const b = tf.scalar(3);
 
// Calling the .div() function over the
// above Tensors as its parameters
a.div(b).print();


Output:

Tensor
   [0.3333333, 3.9999998, 5.6666665, 6.666666]
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS