📜  Tensorflow.js tf.Tensor 类 .clone() 方法

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

Tensorflow.js tf.Tensor 类 .clone() 方法

Tensorflow.js是一个开源库,用于在Javascript中创建机器学习模型,允许用户直接在浏览器中运行模型。

tf.clone()是在tf.Tensor类中定义的函数。它用于创建张量的副本

句法 :

tf.clone( values )

参数:

  • values:它可以是值的张量或值的数组

返回值:返回包含相同元素的张量 价值观

示例 1:输入参数值作为张量

Javascript
// Dynamic loading the "@tensorflow/tfjs" module
const tf = require('@tensorflow/tfjs');
  
//Creating a tensor
var values = tf.tensor([1, 2, 3, 4, 5, 6, 7]);
    
// Printing the colne of a tensor
tf.clone(values).print()


Javascript
// Dynamic loading the "@tensorflow/tfjs" module
const tf = require('@tensorflow/tfjs');
  
//Creating a tensor
var values = [1, 2, 3, 4, 5, 6, 7];
    
// Printing the colne of a tensor
tf.clone(values).print()


输出 :

Tensor
    [1, 2, 3, 4, 5, 6, 7]

示例 2:将参数值作为值数组输入

Javascript

// Dynamic loading the "@tensorflow/tfjs" module
const tf = require('@tensorflow/tfjs');
  
//Creating a tensor
var values = [1, 2, 3, 4, 5, 6, 7];
    
// Printing the colne of a tensor
tf.clone(values).print()

输出 :

Tensor
    [1, 2, 3, 4, 5, 6, 7]

参考: https://js.tensorflow.org/api/latest/#tf.Tensor.clone