Tensorflow.js tf.squaredDifference() Function
Last Updated :
12 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.squaredDifference() function is used to return (a – b) * (a – b) element-wise, where “a” is the first specified tensor and “b” is the second tensor. It Supports broadcasting.
Syntax:
tf.squaredDifference(a, b)
Parameters: This function accepts two parameters which are illustrated below:
- a: The first specified tensor.
- b: The second specified tensor. It must have same data type as “a”.
Return Value: It returns (a – b) * (a – b) element-wise, where “a” is the first specified tensor and “b” is the second tensor.
Example 1:
Javascript
import * as tf from "@tensorflow/tfjs"
const a = tf.tensor1d([1, 3, 5, 7]);
const b = tf.tensor1d([1, 2, 9, 4]);
a.squaredDifference(b).print();
|
Output:
Tensor
[0, 1, 16, 9]
Example 2:
Javascript
import * as tf from "@tensorflow/tfjs"
const a = tf.tensor1d([1, 3, 6, 7]);
const b = tf.scalar(4);
a.squaredDifference(b).print();
|
Output:
Tensor
[9, 1, 4, 9]
Share your thoughts in the comments
Please Login to comment...