Tensorflow.js tf.util.shuffleCombo()函数
Tensorflow.js 是一个由谷歌开发的开源库,用于在浏览器或节点环境中运行机器学习模型以及深度学习神经网络。
.util.shuffleCombo()函数用于在 Fisher-Yates 算法的帮助下按顺序打乱两个声明的数组。
句法:
tf.util.shuffleCombo (array, array2)
参数:
- array1:它是指定的第一个要被洗牌的数组。它可以是 tf.any()[]、Uint32Array、Int32Array 或 Float32Array 类型。
- array2:要打乱的第二个数组。它可以是 tf.any()[]、Uint32Array、Int32Array 或 Float32Array 类型。此外,它使用与第一个数组相同的排列进行改组。
返回值:返回void。
示例 1:
Javascript
// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
// Defining first and second array
const arr = [11, 12, 13, 14, 15];
const arr2 = [16, 17, 18, 19, 20];
// Calling tf.util.shuffleCombo() method and
// printing output
tf.util.shuffleCombo(arr, arr2);
console.log(arr, arr2);
Javascript
// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
// Defining first and second array
// of float values
const arr = [4.5, 6.8, 17.1, 21.23, 45.8];
const arr2 = [47.9, 50.4, 52.5, 62.6, 73.7];
// Calling tf.util.shuffleCombo() method and
// printing output
tf.util.shuffleCombo(arr, arr2);
console.log(arr, arr2);
输出:
12,14,11,15,13 17,19,16,20,18
示例 2:
Javascript
// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
// Defining first and second array
// of float values
const arr = [4.5, 6.8, 17.1, 21.23, 45.8];
const arr2 = [47.9, 50.4, 52.5, 62.6, 73.7];
// Calling tf.util.shuffleCombo() method and
// printing output
tf.util.shuffleCombo(arr, arr2);
console.log(arr, arr2);
输出:
17.1,21.23,45.8,4.5,6.8 52.5,62.6,73.7,47.9,50.4
参考: https://js.tensorflow.org/api/latest/#util.shuffleCombo