Tensorflow.js tf.setdiff1dAsync() Function
Last Updated :
06 Nov, 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.setdiff1dAsync() function is used to find the difference between two specified lists of numbers.
Let’s assume two Tensor “a” and “b” is given, then this function returns a Tensor out which represents all values present in “a” but not in “b”. The returned Tensor out is sorted in the same order in which “a” is represented. This function also returns a Tensor of indices of the number present in the Tensor out.
Syntax:
tf.setdiff1dAsync (a, b)
Parameters: This function accepts two parameters which are illustrated below:
- a: It is a 1-D Tensor of values to keep.
- b: It is a 1-D Tensor of values to exclude in the output. It should have same data type as “a”.
Example 1:
Javascript
import * as tf from "@tensorflow/tfjs"
const a = [10, 20, 30, 40, 50, 60];
const b = [20, 40, 50];
const [out, indices] = await tf.setdiff1dAsync(a, b);
out.print();
indices.print();
|
Output:
Tensor
[10, 30, 60]
Tensor
[0, 2, 5]
Example 2:
Javascript
import * as tf from "@tensorflow/tfjs"
const [out, indices] = await
tf.setdiff1dAsync([0.1, 0, 7.0, 7.1], [.1, 7]);
out.print();
indices.print();
|
Output:
Tensor
[0, 7.0999999]
Tensor
[1, 3]
Reference: https://js.tensorflow.org/api/latest/#setdiff1dAsync
Share your thoughts in the comments
Please Login to comment...