Difference between Variable and get_variable in TensorFlow Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report In this article, we will try to understand the difference between the Variable() and get_variable() function available in the TensorFlow Framework. Variable() Method in TensorFlow A variable maintains a shared, persistent state manipulated by a program. If one uses this function then it will create a new variable. Tensorflow version 2.0 does support variable(). Python3 import tensorflow as tf v = tf.Variable(1.) v.assign(2.) print(v) Output: <tf.Variable 'Variable:0' shape=() dtype=float32, numpy=2.0>get_variable() Method in TensorFlow The get_variable() function creates a new variable called a name(whichever you specify) or adds the existing name of the current scope in the TensorFlow graph. It can be used to create new or add Existing variables. It makes it easier to refactor your code. Python3 import tensorflow as tf s = tf.compat.v1.get_variable(name='tens', shape=[1], dtype=tf.int32) print(s) Output: <tf.Variable 'tens:0' shape=(1,) dtype=int32, numpy=array([0], dtype=int32)> There are times when you are working with GPUs and multiple processors then you would like to use variable sharing as a feature so, let's say you are trying to optimize the weights of a neural network then all the processors must optimize the same parameter parallelly then only we will be able to speed up the training and the optimization process. Comment More infoAdvertise with us Next Article Difference between Variable and get_variable in TensorFlow T thilagavathimfj0 Follow Improve Article Tags : Python Tensorflow Practice Tags : python Similar Reads Difference between Tensor and Variable in Pytorch In this article, we are going to see the difference between a Tensor and a variable in Pytorch. Pytorch is an open-source Machine learning library used for computer vision, Natural language processing, and deep neural network processing. It is a torch-based library. It contains a fundamental set of 3 min read What's the difference between tf.placeholder and tf.Variable? In this article, we are going to see the difference between tf.placeholder and tf.Variable. Â tf.placeholder As the name suggests, it is an empty place. It is an empty variable to which the training data is fed later. The tf.placeholder allows us to create the structure first which is setting up of c 3 min read What's the difference of name scope and a variable scope in tensorflow? When working with TensorFlow, it's important to understand the concepts of name scope and variable scope. These two concepts can be confusing at first, but they are essential to organizing and managing your TensorFlow code. Name scope and variable scope are both used to group related operations and 5 min read Tensorflow.js tf.variable() 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. It helps developers to develop ML models in JavaScript, and use ML directly in the browser or in Node.js. The tf.variable() function i 2 min read 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 Like