Tensorflow.js tf.data.Dataset class.mapAsync() Method Last Updated : 22 Apr, 2022 Comments Improve Suggest changes Like Article Like Report 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 .mapAsync() method is used to map the stated dataset over an asynchronous one to one conversion. Syntax: mapAsync(transform) Parameters: transform: It is the stated function that maps a dataset of items into a Promise for a converted dataset of items. Moreover, such conversion is accountable for discarding some intermediary tensors as in tf.tidy() method where its calculation is wrapped and this can not be programmed here as it is in the synchronous type map() case. It can be of type (value: T) => Promise(tf.void, number, string, TypedArray, tf.Tensor, tf.Tensor[], {[key: string]:tf.Tensor, number, or string}). Return Value: It returns tf.data.Dataset. Example 1: JavaScript // Importing the tensorflow.js library import * as tf from "@tensorflow/tfjs" // Defining dataset formed of an array of // numbers and calling mapAsync() method const res = tf.data.array([16, 12, 13]).mapAsync( y => new Promise(function(rsol){ setTimeout(() => { rsol(y + y); }, Math.sqrt()*400 + 300); })); // Calling toArray() method and // Printing output console.log(await res.toArray()); Output: 32, 24, 26 Example 2: JavaScript // Importing the tensorflow.js library import * as tf from "@tensorflow/tfjs" // Calling mapAsync() method and // Printing output console.log(await tf.data.array([4.5, 8.5]) .mapAsync(y => new Promise(function(tm) { setTimeout(() => { tm(y * y); }) })).toArray()); Output: 20.25, 72.25 Reference: https://js.tensorflow.org/api/latest/#tf.data.Dataset.mapAsync Comment More infoAdvertise with us Next Article Tensorflow.js tf.data.Dataset class.mapAsync() Method nidhi1352singh Follow Improve Article Tags : JavaScript Web Technologies Tensorflow.js TensorFlow.js-Classes TensorFlow.js-Data +1 More Similar Reads Tensorflow.js tf.data.Dataset class .forEachAsync() Method 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 also helps the developers to develop ML models in JavaScript language and can use ML directly in the browser or in Node.js. The tf. 1 min read Tensorflow.js tf.data.Dataset class .take() Method 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 .take() method is used to form a dataset with maximum count foremost items out of the stated dataset. Syntax: take( 2 min read Tensorflow.js tf.data.Dataset class .batch() Method 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 also helps the developers to develop ML models in JavaScript language and can use ML directly in the browser or in Node.js. The tf. 2 min read Tensorflow.js tf.data.Dataset class .toArray() Method 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 .toArray() method is used to accumulate each elements of the stated dataset within an array. Syntax: Â toArray() Pa 1 min read Tensorflow.js tf.data.Dataset class .prefetch() Method 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.data.Dataset class .prefetch() function is used to produce a dataset that prefetches the specified elements from this given dat 2 min read Like