类型错误:“函数”对象在张量流中不可下标

lit*_*ely 3 python-3.x tensorflow

使用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])
Run Code Online (Sandbox Code Playgroud)

但它显示错误:

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])
Run Code Online (Sandbox Code Playgroud)

类型错误:“函数”对象不可下标

我不知道哪里错了,有人可以帮助我吗?(tensorflow的版本是0.12.0)

a p*_*a p 5

当您尝试对没有为下标定义适当方法的内容添加下标时,Python3 会告诉您这一点。

尝试添加下标int

1[1]    
TypeError: 'int' object is not subscriptable
Run Code Online (Sandbox Code Playgroud)

尝试给 a 加上下标function

(lambda: 1)[1]  
TypeError: 'function' object is not subscriptable
Run Code Online (Sandbox Code Playgroud)

但是从 a 中获取值list应该可行

[1,2,3][1]
2
Run Code Online (Sandbox Code Playgroud)

所以,它看起来像是zeros一个函数,可以使用括号调用,但不能使用方括号作为下标。