Monday, November 18, 2024
Google search engine
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 Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments