Thursday, September 4, 2025
HomeLanguagesJavascriptTensorflow.js tf.data.zip() Function

Tensorflow.js tf.data.zip() 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.zip() function is used for creating a dataset by zipping together a dict, array, or nested structure of Dataset.

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]);
 
// Zipping 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"
 
// Zipping 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

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32264 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6629 POSTS0 COMMENTS
Nicole Veronica
11799 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11858 POSTS0 COMMENTS
Shaida Kate Naidoo
6749 POSTS0 COMMENTS
Ted Musemwa
7025 POSTS0 COMMENTS
Thapelo Manthata
6698 POSTS0 COMMENTS
Umr Jansen
6716 POSTS0 COMMENTS