码迷,mamicode.com
首页 > 其他好文 > 详细

AttributeError: module 'tensorflow' has no attribute 'sub'

时间:2019-03-09 09:14:49      阅读:1415      评论:0      收藏:0      [点我收藏+]

标签:nbsp   import   class   ack   imp   ssi   rac   ini   style   

 

官方的例子:运行之后出现以下错误

# 进入一个交互式 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.]

 

Traceback (most recent call last):
  File "C:\Users\lzm\Desktop\ten-1.py", line 10, in <module>
    sub = tf.sub(x, a)
AttributeError: module tensorflow has no attribute sub

 

出现这个问题是因为sub函数换名字了,换成了subtract 

# 进入一个交互式 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.subtract(x, a)
print sub.eval()
# ==> [-2. -1.]

 

AttributeError: module 'tensorflow' has no attribute 'sub'

标签:nbsp   import   class   ack   imp   ssi   rac   ini   style   

原文地址:https://www.cnblogs.com/QW-lzm/p/10499013.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!