Saturday, February 7, 2026
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
32492 POSTS0 COMMENTS
Milvus
126 POSTS0 COMMENTS
Nango Kala
6863 POSTS0 COMMENTS
Nicole Veronica
11987 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12079 POSTS0 COMMENTS
Shaida Kate Naidoo
6996 POSTS0 COMMENTS
Ted Musemwa
7239 POSTS0 COMMENTS
Thapelo Manthata
6947 POSTS0 COMMENTS
Umr Jansen
6934 POSTS0 COMMENTS