Tensorflow.js tf.neg() Function
Last Updated :
18 May, 2021
Tensorflow.js is an open-source library which is being developed by Google for running machine learning models as well as deep learning neural networks in the browser or node environment.
The .neg() function is used to calculate -1 * x i.e. input tensor and is done element wise.
Syntax:
tf.neg(x)
Parameters:
- x: It is the tensor input, and it can be of type tf.Tensor, or TypedArray, or Array.
Return Value: It returns the tf.Tensor object.
Example 1:
Javascript
import * as tf from "@tensorflow/tfjs"
const y = tf.tensor2d([6, 0, -9, -1], [4, 1]);
y.neg().print();
|
Output:
Tensor
[[-6],
[0 ],
[9 ],
[1 ]]
Example 2: In this example, the parameter is passed directly to the neg function.
Javascript
import * as tf from "@tensorflow/tfjs"
const y = tf.tensor2d([
1.4, 0.98, -9.9, -1.5, 2.0, 6.5], [2, 3]);
var res = tf.neg(y);
res.print();
|
Output:
Tensor
[[-1.4, -0.98, 9.8999996],
[1.5 , -2 , -6.5 ]]
Reference: https://js.tensorflow.org/api/latest/#neg
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...