Tensorflow.js tf.reciprocal() Function
Last Updated :
10 May, 2021
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
import * as tf from "@tensorflow/tfjs"
const x = tf.tensor1d([2, 3, 4, 5]);
x.reciprocal().print();
|
Output:
Tensor
[0.5, 0.3333333, 0.25, 0.2]
Example 2:
Javascript
import * as tf from "@tensorflow/tfjs"
tf.tensor1d([0, 1, -2, 1.7, -2.5]).reciprocal().print();
|
Output:
Tensor
[Infinity, 1, -0.5, 0.5882353, -0.4]
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...