Tensorflow.js tf.equal() 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.equal() function is used to return the tensor of Boolean values for the two specified tensor values i.e. it returns true if the value of the first tensor is equal to the second tensor value else returns false. It supports broadcasting.
Syntax:
tf.equal(a, b)
Parameters: This function accepts two parameters which are illustrated below:
- a: The first input tensor.
- b: The second input tensor. It should have values of the same data type as of tensor “a”.
Return Value: It returns the tensor of Boolean values i.e. true if the value of the first tensor is equal to the second tensor value else returns false.
Example 1:
Javascript
import * as tf from "@tensorflow/tfjs"
const a = tf.tensor1d([2, 4, 6, 8]);
const b = tf.tensor1d([1, 4, 7, 8]);
a.equal(b).print();
|
Output:
Tensor
[false, true, false, true]
Example 2:
Javascript
import * as tf from "@tensorflow/tfjs"
tf.tensor1d([1.5, 2.6, 2, 0.5, 4.5]).
equal(tf.tensor1d([1.5, 2.60, 2.0, .5, 4.05])).print();
|
Output:
Tensor
[true, true, true, true, false]
Reference: https://js.tensorflow.org/api/latest/#equal
Share your thoughts in the comments
Please Login to comment...