Open In App

Tensorflow.js tf.data.Dataset.map() 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 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.data.Dataset.map() function is used to map the dataset through a 1-to-1 transform.



Syntax:

map(transform) 

Parameters:



Return Value: It returns tf.data.Dataset.

Example 1:




const gfg = tf.data.array([1, 2, 3]).map(x => x*x);
  
await gfg.forEachAsync(geeks => console.log(geeks));

Output:

1
4
9

Example 2:




const gfg = tf.data.array([10, 20, 30]).map(x => x+20/x);
  
await gfg.forEachAsync(geeks => console.log(geeks));

Output:

12
21
30.666666666666668

Reference: https://js.tensorflow.org/api/latest/#tf.data.Dataset.map

Article Tags :