Tensorflow.js tf.clone() Function Last Updated : 19 Oct, 2021 Comments Improve Suggest changes Like Article Like Report Tensorflow.js is an open-source library developed by Google for running machine learning models and deep learning neural networks in the browser or node environment. The tf.clone() function is used to create a copy of a tensor. The tf.clone() function creates a new tensor of the same shape and value of another tensor. Syntax: tf.clone( x ) Parameters: x: It is the tensor which we want to clone. Its value can be tensor, Array, TypedArray type. Returns: It returns a Tensor Object. Example 1: In this example, we are creating a copy of the tensor x and storing it into y. JavaScript // Importing the tensorflow.js library import * as tf from "@tensorflow/tfjs" // Creating a tensor object const x = tf.tensor([6, 1]); // Cloning the tensor x and // storing it into y const y = tf.clone(x); // Printing the tensor y.print(); Output : [6, 1] Example 2: In this example, we cloned the tensor x using x.clone() instead of tf.clone(x). JavaScript import * as tf from "@tensorflow/tfjs" // Creating a tensor object const x = tf.tensor([12, 2]); // Cloning the tensor x const y = x.clone(); // Printing the tensor y.print(); Output : [12, 2] Example 3: Have a look at the example below. JavaScript // Creating a tensor x const x = tf.tensor([2, 2]); // Creating a clone of tensor x // using clone() function const y = x.clone(); // Creating a tensor a and // storing the same value as x const a = tf.tensor([2, 2]); // Copying the value of a into // b using assignment operator const b = a; console.log(x == y); // false console.log(x === y); // false console.log(a == x); // false console.log(a == b); // true console.log(a === b); // true Output : false false false true true Reference: https://js.tensorflow.org/api/latest/#clone Create Quiz Comment G gfgking Follow 0 Improve G gfgking Follow 0 Improve Article Tags : JavaScript Web Technologies Tensorflow.js Explore JavaScript BasicsIntroduction to JavaScript4 min readVariables and Datatypes in JavaScript6 min readJavaScript Operators5 min readControl Statements in JavaScript4 min readArray & StringJavaScript Arrays7 min readJavaScript Array Methods7 min readJavaScript Strings5 min readJavaScript String Methods9 min readFunction & ObjectFunctions in JavaScript5 min readJavaScript Function Expression3 min readFunction Overloading in JavaScript4 min readObjects in JavaScript4 min readJavaScript Object Constructors4 min readOOPObject Oriented Programming in JavaScript3 min readClasses and Objects in JavaScript4 min readWhat Are Access Modifiers In JavaScript ?5 min readJavaScript Constructor Method7 min readAsynchronous JavaScriptAsynchronous JavaScript2 min readJavaScript Callbacks4 min readJavaScript Promise4 min readEvent Loop in JavaScript4 min readAsync and Await in JavaScript2 min readException HandlingJavascript Error and Exceptional Handling6 min readJavaScript Errors Throw and Try to Catch2 min readHow to create custom errors in JavaScript ?2 min readJavaScript TypeError - Invalid Array.prototype.sort argument1 min readDOMHTML DOM (Document Object Model)8 min readHow to select DOM Elements in JavaScript ?3 min readJavaScript Custom Events4 min readJavaScript addEventListener() with Examples9 min readAdvanced TopicsClosure in JavaScript4 min readJavaScript Hoisting6 min readScope of Variables in JavaScript3 min readJavaScript Higher Order Functions7 min readDebugging in JavaScript4 min read Like