Skip to content
Related Articles

Related Articles

Improve Article

Tensorflow.js tf.data.zip() Function

  • Last Updated : 01 Jun, 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.zip() function is used for creating a dataset by zipping together a dict, array, or nested structure of Dataset.

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: 

tf.data.zip(datasets)

Parameters:



  • dataset: It is the set of data.

Return Value: It returns the tf.data.Dataset.

Example 1:

Javascript




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Initializing Array dataset.
let geek1 = tf.data.array([1, 2, 3, 4]);
let geek2 = tf.data.array([5, 6, 7, 8]);
  
// Ziping dataset of objects.
let geek3 = tf.data.zip([geek1, geek2]);
  
// Printing the returned promise.  
await geek3.forEachAsync(function(geek){
  console.log(JSON.stringify(geek))
});

Output:

[1,5]
[2,6]
[3,7]
[4,8]

Example 2:

Javascript




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Ziping two array dataset.
let geek = tf.data.zip({
    geek1: tf.data.array([1, 2, 3, 4]), 
    geek2: tf.data.array([5, 6, 7, 8])
});
  
// Printing the result.
await geek.forEachAsync(function(e){
  console.log(JSON.stringify(e))
});

Output:

{"geek1":1,"geek2":5}
{"geek1":2,"geek2":6}
{"geek1":3,"geek2":7}
{"geek1":4,"geek2":8}

Reference:   https://js.tensorflow.org/api/3.6.0/#tf.data.zip




My Personal Notes arrow_drop_up
Recommended Articles
Page :