Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Tensorflow.js tf.data.Dataset.filter() 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.filter() function is used to filter the dataset according to predicate.

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!

Syntax:

filter(predicate)

Parameters:



  • predicate: A function mapping a dataset element to a boolean or a Promise for one.

Return Value: It returns tf.data.Dataset

Example 1:

Javascript




const gfg = tf.data.array([8, 12, 25, 6, 34, 2, 67, 43])
   .filter(x => x >= 10);
await gfg.forEachAsync(geeks => console.log(geeks));

Output:

12
25
34
67
43

Example 2:

Javascript




const gfg = tf.data.array([10, 21, 36, 24, 54, 65, 72, 90, 95, 12])
   .filter(x => x%6 === 0);
await gfg.forEachAsync(geeks => console.log(geeks));

Output:

36
24
54
72
90
12

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

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!