Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: 'function' object is not subscriptable in tensorflow

There are some errors using tensorflow.Varaible:

import tensorflow as tf
sess = tf.InteractiveSession()
x = tf.placeholder(tf.float32,[None, 784])
W = tf.Variable(tf.zeros[784,10])
b = tf.Variable(tf.zeros[10])

but it shows error:

TypeError:Traceback (most recent call last)
<ipython-input-8-3086abe5ee8f> in <module>()
----> 1 W = tf.Variable(tf.zeros[784,10])
  2 b = tf.Variable(tf.zeros[10])

TypeError: 'function' object is not subscriptable

I don't know where is wrong, can someone help me?(The version of tensorflow is 0.12.0)

like image 958
littlely Avatar asked Jan 19 '26 17:01

littlely


2 Answers

This is what Python3 tells you when you try to subscript something that doesn't have the appropriate methods defined for subscripting.

Try to subscript an int:

1[1]    
TypeError: 'int' object is not subscriptable

Try to subscript a function:

(lambda: 1)[1]  
TypeError: 'function' object is not subscriptable

But getting a value from a list should work

[1,2,3][1]
2

So, it looks like zeros is a function, which can be called using parens but not subscripted into using brackets.

like image 170
a p Avatar answered Jan 21 '26 08:01

a p


W=tf.Variable(tf.zeros([784,10]))
b=tf.Variable(tf.zeros([10]))
like image 36
shashanka300 Avatar answered Jan 21 '26 06:01

shashanka300