Related Articles

# Tensorflow.js tf.mod() Function

• Last Updated : 25 May, 2021

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.mod() function returns element-wise remainder of division.

Operation: floor(x / y) * y + mod(x, y) = x.

Syntax:

`tf.mod(x, y).`

Parameters: This function accepts three parameters which are illustrated below:

• x: It is a Tensor.
• y: It is a Tensor. It must be of the same type as x.

Return Value: A Tensor. Has the same type as x.

Example 1: We also expose tf.mod() which has the same signature as this operation and asserts that a and b have the same shape (does not broadcast).

## Javascript

 `// Importting the tensorflow.js library``import * as tf from ``"@tensorflow/tfjs"`` ` `// Creating the tensor``const x = tf.tensor([9, 12, 3, 20, 7]);``const y = tf.tensor([2, 2, 9, 4, 2]);`` ` `tf.mod(x,y).print();`

Output:

```Tensor
[1, 0, 3, 0, 1]```

Example 2: The simplest broadcasting example when an array and a scalar value are combined in an operation:

## Javascript

 `// Importing the tensorflow library``import * as tf from ``"@tensorflow/tfjs"`` ` `// Broadcast a mod b.``const x = tf.tensor([2, 4, 5, 8]);``const y = tf.scalar(5);`` ` `x.mod(y).print();`

Output:

```Tensor
[2, 4, 0, 3]```

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it’s lowest price ever!

My Personal Notes arrow_drop_up