Skip to content
Related Articles

Related Articles

Tensorflow.js tf.pow() Function

View Discussion
Improve Article
Save Article
  • Last Updated : 12 May, 2021
View Discussion
Improve Article
Save 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.pow() function is used to compute the power of one specified tensor to another. It supports broadcasting.

Syntax:

tf.power(base, exp).

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

  • base: The specified base component element wise for the given tensor.
  • exp: The specified exponent component element wise for the given tensor.

Return Value: It returns a tensor for the computed result of power operation.

Example 1:

Javascript




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Initializing Tensor "a" as base and
// "b" as exponent values
const a = tf.tensor([2])
const b = tf.tensor([3])
  
// Calling the pow() function over
// the above tensor as its parameters
a.pow(b).print();


Output:

Tensor
   [8]

Example 2:

Javascript




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Initializing Tensor "a" as base and
// "b" as exponent values
const a = tf.tensor([[1, 2], [3, 4]])
const b = tf.tensor([2])
  
// Calling the pow() function over
// the above tensor as its parameters
a.pow(b).print();


Output:

Tensor
   [[1, 4 ],
    [9, 16]]
My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!