Open In App

Tensorflow.js tf.Tensor class .clone() Method

Improve
Improve
Like Article
Like
Save
Share
Report

Tensorflow.js is an open-source library for creating machine learning models in Javascript that allows users to run the models directly in the browser.

The tf.clone() is a function defined in the class tf.Tensor. It’s used to create a replica of a tensor.

Syntax :

tf.clone( values )

Parameters:

  • values: It can be a tensor of values or an array of values

Return value: It returns the tensor containing elements the same as of values.

Example 1: Input parameter values as a tensor

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


Output :

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

Example 2: Input parameter values as an array of values

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


Output :

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

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


Last Updated : 22 Apr, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads