Skip to content
Related Articles
Get the best out of our app
GFG App
Open App
geeksforgeeks
Browser
Continue

Related Articles

Tensorflow.js tf.rsqrt() Function

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

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

Syntax:

tf.rsqrt (x)

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

  • x: The specified input tensor.

Return Value: It returns the reciprocal of square root 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 .rsqrt() function over
// the above tensor as its parameter
x.rsqrt().print();


Output:

Tensor
   [0.7071068, 0.5773503, 0.5, 0.4472136]

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 .rsqrt() function
tf.tensor1d([0, 1, -2, 1.7, -2.5]).rsqrt().print();


Output:

Tensor
   [Infinity, 1, NaN, 0.766965, NaN]
My Personal Notes arrow_drop_up
Last Updated : 10 May, 2021
Like Article
Save Article
Similar Reads
Related Tutorials