Open In App

Tensorflow.js tf.sqrt() Function

Improve
Improve
Like Article
Like
Save
Share
Report

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

Syntax: 

tf.sqrt( x )

Parameters: This function accept single parameter which is illustrated below:

  • x: The specified input tensor.

Return Value: It returns the square root of the specified tensor’s element.

Example 1:

Javascript




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


Output:

Tensor
   [2, 3, 4, 5]

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


Output:

Tensor
   [0, 1, 1.4142135, 1.3038405, 1.5811388]

Last Updated : 10 May, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads