zoukankan      html  css  js  c++  java
  • AttributeError: module 'tensorflow' has no attribute 'sub'

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

    # 进入一个交互式 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:UserslzmDesktop	en-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.]
  • 相关阅读:
    MySQL查看视图
    MySQL创建视图(CREATE VIEW)
    Mysql视图
    Snipaste使用教程
    Mysql全文检索
    MySQL中MyISAM和InnoDB
    MySQL卸载注意事项
    MySql免安装配置(Windows)
    验证用户名密码:Servlet+Maven+Mysql+jdbc+Jsp
    使用response下载文件
  • 原文地址:https://www.cnblogs.com/QW-lzm/p/10499013.html
Copyright © 2011-2022 走看看