Tensorflow.js tf.variable() Function Last Updated : 07 Jul, 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. It helps developers to develop ML models in JavaScript, and use ML directly in the browser or in Node.js. The tf.variable() function is used to create a new variable with the provided initial value. Syntax: tf.variable(initialValue, trainable, name, dtype) Parameters: initialValue: The initial value of the tensor from which the new variable will be initialized.trainable: It is an optional parameter. It is of boolean type if true optimizers are allowed to update the variable and if false optimizers are not allowed to update it.name: It is also an optional parameter. It is of string type. It is used for the name of the variable used as a unique ID.dtype: It is also an optional parameter. If it is passed as the argument the intialValue will be changed to the specified dtype. Return Value: This function returns tf.variable. Example 1: JavaScript // Creating and initializing a new variable var val = tf.variable(tf.tensor2d( [8, 2, 5, 6], [2, 2] )); // Printing the tensor val.print() Output: Tensor [[8, 2], [5, 6]] Example 2: JavaScript // Creating and initializing a new variable var val = tf.variable(tf.tensor([1, 2, 5, 6])); // Printing the tensor val.print() Output: Tensor [1, 2, 5, 6] Example 3: JavaScript // Creating and initializing a new variable const x = tf.variable(tf.tensor([1, 2, 3]), true,"gfg",'complex64'); // Printing the tensor x.print(); Output: Tensor [1 + 0j, 2 + 0j, 3 + 0j] Reference: https://js.tensorflow.org/api/latest/#variable Comment More infoAdvertise with us Next Article Tensorflow.js tf.variable() Function C CoderSaty Follow Improve Article Tags : JavaScript Web Technologies Tensorflow.js Similar Reads Tensorflow.js tf.variableGrads() Function Tensorflow.js is an open-source library that is developed by Google for running machine learning models as well as deep learning neural networks in the browser or node environment. The .variableGrads() function is used to calculate as well as return the gradient of f(x) in comparison to the stated l 2 min read Tensorflow.js tf.tile() Function TensorFlow.js is a library for machine learning in JavaScript. It helps developers to develop ML models in JavaScript, and use ML directly in the browser or in Node.js. The tf.tile() function is used to create a Tensor by repeating the number of times given by reps. Syntax: tf.tile(x, reps)Note: Thi 2 min read Tensorflow.js tf.unique() 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 .unique() function is used to find unique elements along an axis of a tensor. Â Syntax: tf.unique (x, axis?) 2 min read Tensorflow.js tf.zerosLike() 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.zeroslIke() is used to create a tf.tensor with all elements set to '0' with the same shape as the given tensor by passing the p 3 min read Tensorflow.js tf.tidy() Function Tensorflow.js is an open-source library that is developed by Google for running machine learning models as well as deep learning neural networks in the browser or node environment. The .tidy() function is used to execute the given function i.e. fn and once its terminated it clears up all the equidis 3 min read Like