Module 'Tensorflow' Has No Attribute 'Variable' in Google Colaboratory

I'm trying to create a variable tensor in google Collaboratory with this code, but error because TensorFlow doesn't have a module about variables. what's the solution?

import tensorflow as tf
var_1 = tf.variable(tf.ones([2,3]))

Error:

AttributeError                            Traceback (most recent call last)
    <ipython-input-2-2666f49bf801> in <module>()
    ----> 1 var_1 = tf.variable(tf.ones([2,3]))
    
AttributeError: module 'tensorflow' has no attribute 'variable'
2

1 Answer

There is a typo error. Use capital letter V for Variable.

You can refer below code for the same.

import tensorflow as tf

var_1 = tf.Variable(tf.ones([2,3]))

var_1

Click here, for more details

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

James H. Sterling

James H. Sterling

Environmental Science & Climate Journalist

James Sterling reports on renewable energy developments, climate policy, ecological conservation, and green tech innovations around the globe.

Share this article
Twitter Facebook Pinterest