在照着tensorflow 官方文檔和極客學院中tensorflow中文文檔學習tensorflow時,遇到下面的兩個問題:函數
#進入一個交互式Tensorflow會話 import tensorflow as tf sess = tf.InteractiveSession() x = tf.Variable([1.0,2.0]) a = tf.constant([3.0,3.0]) #使用初始化器initalizer op的run()方法初始化'x' x.initializer.run() #增長一個減法sub op, 從'x'減去'a',運行減去op,輸出結果 sub = tf.sub(x,a) print(sub.eval()) # 任務完成,關閉回話 sess.close()
執行時報錯:學習
Traceback (most recent call last): File "C:/PythonProj/tensorflow/first_tensorflow.py", line 43, in <module> sub = tf.sub(x,a) AttributeError: module 'tensorflow' has no attribute 'sub'
通過在pycharm中tf.自動反顯的信息,我發現原來這個sub函數已經被subtract代替了,換成tf.subtract(x,a) ,ok ,一切順利!spa
input1 = tf.constant(3.0) input2 = tf.constant(2.0) input3 = tf.constant(5.0) intermed = tf.add(input2,input3) mul = tf.mul(input1,intermed) with tf.Session() as sess: result = sess.run([mul,intermed]) print(result)
報錯信息爲:code
Traceback (most recent call last): File "C:/PythonProj/tensorflow/first_tensorflow.py", line 78, in <module> mul = tf.mul(input1,intermed) AttributeError: module 'tensorflow' has no attribute 'mul'
同理,通過在pycharm中tf.反顯信息的觀察,我發現原來這個tf.mul函數已經被換成了tf.multiply了,修改後,ok!blog