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 Comment More infoAdvertise with us Next Article Tensorflow.js tf.clone() Function G gfgking Follow Improve Article Tags : JavaScript Web Technologies Tensorflow.js Similar Reads Tensorflow.js tf.concat() Function 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.concat() function is used to concatenate the list of specified Tensors along the given axis. Syntax: tf.concat (tensors, axis)P 2 min read Tensorflow.js tf.conv2d() Function Tensorflow.js is a javascript library developed by Google to run and train machine learning models in the browser or in Node.js. The tf.conv2d() function is used to compute 2d convolutions over the given input. In a deep neural network, we use this convolution layer which creates a convolution kern 4 min read Tensorflow.js tf.eye() Function 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.eye() is a function defined in the class tf.Tensor. Itâs used to create an identity matrix of specified rows and columns. An identity matrix 3 min read Tensorflow.js tf.floor() Function Tensorflow.js is an open-source library that is being developed by Google for running machine learning models as well as deep learning neural networks in the browser or node environment. The .floor() function is used to find the floor of the stated tensor input and is done elements wise. Syntax : 2 min read Tensorflow.js tf.elu() Function Tensorflow.js is an open-source library that is being developed by Google for running machine learning models as well as deep learning neural networks in the browser or node environment. The .elu() function is used to find the exponential linear of the stated tensor input and is done elements wise. 2 min read Like