Skip to content
Related Articles

Related Articles

Improve Article

Tensorflow.js tf.data.Dataset.map() Function

  • Last Updated : 25 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. 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:

  • transform: A function mapping a dataset element to a transformed dataset element.

Return Value: It returns tf.data.Dataset.



Example 1:

Javascript




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:

Javascript




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

My Personal Notes arrow_drop_up
Recommended Articles
Page :