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 Difference Between tf.Session() And tf.InteractiveSession() Functions in Python Tensorflow In this article, we are going to see the differences between  tf.Session() and tf.InteractiveSession(). tf.Session() In TensorFlow, the computations are done using graphs. But when a graph is created, the values and computations are not defined. So a session is used to run the graph. The sessions pl 2 min read How to Print the Value of a Tensor Object in TensorFlow TensorFlow is a powerful open-source library for machine learning and deep learning applications. It allows developers to create complex computational graphs and perform operations on tensors, which are multi-dimensional arrays. Understanding how to print the value of a tensor object in TensorFlow i 4 min read Difference Between Dataset.from_tensors and Dataset.from_tensor_slices In this article, we will learn the difference between from_tensors and from_tensor_slices. Both of these functionalities are used to iterate a dataset or convert a data to TensorFlow data pipeline but how it is done difference lies there. Suppose we have a dataset represented as a Numpy matrix of sh 3 min read Python - tensorflow.IndexedSlices.values Attribute TensorFlow is open-source Python library designed by Google to develop Machine Learning models and deep learning  neural networks. values is used to get the values of the slice. Syntax: tensorflow.IndexedSlices.values Returns: It returns a Tensor containing the values of the slice. Example 1: Python 1 min read Variables in Tensorflow TensorFlow is a Python library for efficient numerical computing. It's a foundation library that can be used to develop machine learning and deep learning models. Tensorflow is a high-level library. A variable is a state or value that can be modified by performing operations on it. In TensorFlow var 5 min read Like