Saturday, October 25, 2025
HomeLanguagesJavascriptTensorflow.js tf.data.Dataset.map() Function

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:

  • 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(neveropen => console.log(neveropen));


Output:

1
4
9

Example 2:

Javascript




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


Output:

12
21
30.666666666666668

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

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS