Skip to content
Related Articles

Related Articles

Save Article
Improve Article
Save Article
Like Article

Tensorflow.js tf.util.shuffle() Function

  • Last Updated : 21 May, 2021

Tensorflow.js is an open-source library which is being develop by Google for running machine learning models as well as deep learning neural networks in the browser or node environment.

The .util.shuffle() function is used to shuffle the stated array in order with the help of Fisher-Yates algorithm.

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.util.shuffle(array)

Parameters:  



  • array: It is the stated array which is to be shuffled. It can be of type tf.any()[], Uint32Array, Int32Array, or, Float32Array.

Return Value: It returns void.

Example 1:

Javascript




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Defining array
const arr = [11, 12, 13, 14, 15];
  
// Calling tf.util.shuffle() method and
// printing output
tf.util.shuffle(arr);
console.log(arr);

Output:

14,12,11,13,15

Example 2:

Javascript




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Defining array of float values
const arr = [1.1, 1.2, 1.3, 1.4, 1.5];
  
// Calling tf.util.shuffle() method and
// printing output
tf.util.shuffle(arr);
console.log(arr);

Output:

1.5,1.2,1.3,1.1,1.4

Reference: https://js.tensorflow.org/api_node/2.0.1/#util.shuffle

My Personal Notes arrow_drop_up
Recommended Articles
Page :