📜  Tensorflow.js tf.util.createShuffledIndices()函数

📅  最后修改于: 2022-05-13 01:56:27.768000             🧑  作者: Mango

Tensorflow.js tf.util.createShuffledIndices()函数

Tensorflow.js 是一个由谷歌开发的开源库,用于在浏览器或节点环境中运行机器学习模型以及深度学习神经网络。

.util.createShuffledIndices()函数用于创建一个新数组,该数组根据规定的数量具有随机索引。

语法:此函数接受以下参数。

tf.util.createShuffledIndices(n)

参数:

  • n:索引随机打印的编号。

返回值:它返回Uint32Array

示例 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);


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));


输出:

Uint32Array(11) [
  9, 5, 4, 6,  7,
  8, 0, 1, 2, 10,
  3
]

示例 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));

输出:

Uint32Array(10) [
  5, 1, 9, 2, 0, 
  4, 8, 7, 6, 3  
]

参考: https://js.tensorflow.org/api/latest/#util.createShuffledIndices