Sunday, January 18, 2026
HomeLanguagesJavascriptTensorflow.js tf.reciprocal() Function

Tensorflow.js tf.reciprocal() 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.reciprocal() function is used to return the reciprocal of the specified tensor’s elements.

Syntax:

tf.reciprocal(x)

Parameters: This function accepts a parameter which is illustrated below:

  • x: The specified input tensor.

Return Value: It returns the reciprocal of the specified tensor’s elements.

Example 1:

Javascript




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Initializing a tensor of some elements
const x = tf.tensor1d([2, 3, 4, 5]);
  
// Calling the .reciprocal() function over
// the above tensor as its parameter
x.reciprocal().print();


Output:

Tensor
   [0.5, 0.3333333, 0.25, 0.2]

Example 2:

Javascript




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Using a tensor of some elements
// as the parameter for the .reciprocal() function
tf.tensor1d([0, 1, -2, 1.7, -2.5]).reciprocal().print();


Output:

Tensor
   [Infinity, 1, -0.5, 0.5882353, -0.4]
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
32474 POSTS0 COMMENTS
Milvus
118 POSTS0 COMMENTS
Nango Kala
6846 POSTS0 COMMENTS
Nicole Veronica
11977 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12063 POSTS0 COMMENTS
Shaida Kate Naidoo
6985 POSTS0 COMMENTS
Ted Musemwa
7219 POSTS0 COMMENTS
Thapelo Manthata
6933 POSTS0 COMMENTS
Umr Jansen
6911 POSTS0 COMMENTS