Open In App

Tensorflow.js tf.pow() 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.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:



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

Example 1:




// 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:




// 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]]
Article Tags :