Tensorflow.js tf.setdiff1dAsync() Function Last Updated : 06 Nov, 2021 Comments Improve Suggest changes Like Article Like Report 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 // Importing the tensorflow.js library import * as tf from "@tensorflow/tfjs" // Initializing two Tensors const a = [10, 20, 30, 40, 50, 60]; const b = [20, 40, 50]; // Calling the .setdiff1dAsync() function over // the above two specified Tensors as parameters // and returns the Tensor out and indices for // the same const [out, indices] = await tf.setdiff1dAsync(a, b); // Getting the Tensor of values present in // Tensor "a" but not in "b" out.print(); // Getting the Tensor of indices for the // returned Tensor's values indices.print(); Output: Tensor [10, 30, 60] Tensor [0, 2, 5] Example 2: JavaScript // Importing the tensorflow.js library import * as tf from "@tensorflow/tfjs" // Using two Tensors as the parameters for the // .setdiff1dAsync() function and // returns the Tensor out and indices const [out, indices] = await tf.setdiff1dAsync([0.1, 0, 7.0, 7.1], [.1, 7]); // Getting the Tensor of values present in // Tensor first Tensor parameter // but not in second one out.print(); // Getting the Tensor of indices for the // returned Tensor's values indices.print(); Output: Tensor [0, 7.0999999] Tensor [1, 3] Reference: https://js.tensorflow.org/api/latest/#setdiff1dAsync Comment More infoAdvertise with us Next Article Tensorflow.js tf.setdiff1dAsync() Function K Kanchan_Ray Follow Improve Article Tags : JavaScript Web Technologies Tensorflow.js TensorFlow.js-Transformations Similar Reads Tensorflow.js tf.stack() Function 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. It helps developers to develop ML models in JavaScript, and use ML directly in the browser or in Node.js. The tf.stack() function is u 2 min read Tensorflow.js tf.tan() Function Tensorflow.js is an open-source library that is being developed by Google for running machine learning models as well as deep learning neural networks in the browser or node environment. The .tan() function is used to find the tangent of the stated tensor input and is done element wise. Syntax: tf.t 2 min read Tensorflow.js tf.tanh() Function Tensorflow.js is an open-source library that is being developed by Google for running machine learning models as well as deep learning neural networks in the browser or node environment. The .tanh() function is used to find the hyperbolic tangent of the stated tensor input and is done elements wise. 2 min read Tensorflow.js tf.sinh() function 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 .sinh() function is used to find the hyperbolic sin of the stated tensor input and is done elements wise. Sy 2 min read Tensorflow.js tf.ready() Function Introduction: Tensorflow.js is an open-source library that is developed by Google for running machine learning models as well as deep learning neural networks in the browser or node environment. The .ready() function is used to return a promise which determines at what time the recently picked backe 1 min read Tensorflow.js tf.squaredDifference() Function 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" 2 min read Tensorflow.js tf.min() Function 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.min() function is used to calculate the minimum value from the specified Tensor across its dimension. It reduces the given inpu 2 min read Tensorflow.js tf.nextFrame() Function Introduction: Tensorflow.js is an open-source library that is developed by Google for running machine learning models as well as deep learning neural networks in the browser or node environment. The .nextFrame() function is used to return a promise which determines at which a requestAnimationFrame 2 min read Tensorflow.js tf.ones() Function Tensorflow.js is an open-source library for running machine learning models and deep learning neural networks in the browser or node environment. The tf.ones() function is used to create a new tensor where all elements are set to 1. Syntax: tf.ones(shape, dtype, name) Parameters: shape: It takes the 2 min read Tensorflow.js tf.step() Function 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.step() function is used to return the step of the input tensor's elements i.e. it returns 1 if the element is greater than 0 el 1 min read Like