Tensorflow.js is an open-source library that is being developed by Google for running machine learning models as well as deep learning neural networks in the browser or node environment.
The .util.createShuffledIndices() function is used to create a new array that has randomized indices according to the stated quantity.
Syntax: This function accepts the following parameter.
tf.util.createShuffledIndices(n)
Parameters:
- n: It is the number according to which the indexes are printed randomly.
Return Value: It returns Uint32Array.
Example 1:
Javascript
// Importing the tensorflow.js library import * as tf from "@tensorflow/tfjs" // Calling util.createShuffledIndices() method // and printing output const randm_indxes = tf.util.createShuffledIndices(11); console.log(randm_indxes); |
Output:
Uint32Array(11) [ 9, 5, 4, 6, 7, 8, 0, 1, 2, 10, 3 ]
Example 2:
Javascript
// Importing the tensorflow.js library import * as tf from "@tensorflow/tfjs" // Defining n var num = (5*2*1) // Calling util.createShuffledIndices() method // and printing output console.log(tf.util.createShuffledIndices(num)); |
Output:
Uint32Array(10) [ 5, 1, 9, 2, 0, 4, 8, 7, 6, 3 ]
Reference: https://js.tensorflow.org/api/latest/#util.createShuffledIndices