'tensorflow' has no attribute 'sub'

'tensorflow' has no attribute 'sub'

在学习tensorflow的时候,照到官方的例子做,发现了一个:

# 进入一个交互式 TensorFlow 会话.
import tensorflow as tf
sess = tf.InteractiveSession()

x = tf.Variable([1.0, 2.0])
a = tf.constant([3.0, 3.0])

# 使用初始化器 initializer op 的 run() 方法初始化 'x' 
x.initializer.run()

# 增加一个减法 sub op, 从 'x' 减去 'a'. 运行减法 op, 输出结果 
sub = tf.sub(x, a)
print sub.eval()
# ==> [-2. -1.]
AttributeError: module 'tensorflow' has no attribute 'sub'
估计是函数换名字了,果然换成 subtract 就可以了。

猜你喜欢

转载自blog.csdn.net/liubing8609/article/details/80560728