第一次運行 TensorFlow

$ python? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?//打開python終端

>>> import tensorflow as tf? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //引入tensorflow

>>> hello = tf.constant('Hello, TensorFlow!')? ? ?// 創(chuàng)建一個常量 hello?

>>> sess = tf.Session()? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?//創(chuàng)建一個會話(Session)

>>>print (sess.run(hello))? ? ? ? ? ? ? ? ? ? ? ? ? ? //注意python2和python3的語法

Hello, TensorFlow!

>>> a = tf.constant(10)? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ?//?創(chuàng)建一個常量?a

>>> b = tf.constant(32)? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ?//?創(chuàng)建一個常量?b

>>>print (sess.run(a+b))? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?// sess.run(a+b)運行a+b

42

>>>


1、tf.constant(value,dtype=None,shape=None,name='Const')

? ? ? ?創(chuàng)建一個常量tensor,先給出value,可以設定其shape

????# Constant 1-D Tensor populated with value list.

????????tensor = tf.constant([1,2,3,4,5,6,7]) => [1234567]

????# Constant 2-D tensor populated with scalar value -1.

????????tensor = tf.constant(-1.0, shape=[2,3]) => [[-1.-1.-1.] [-1.-1.-1.]

?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

  • TF API數(shù)學計算tf...... :math(1)剛開始先給一個運行實例。tf是基于圖(Graph)的計算系統(tǒng)...
    MachineLP閱讀 4,066評論 0 1
  • 簡單線性回歸 import tensorflow as tf import numpy # 創(chuàng)造數(shù)據(jù) x_dat...
    CAICAI0閱讀 3,669評論 0 49
  • 能把本業(yè)之外的寫作這件事做的特別好的人,男的我服氣海巖,女的我認畢淑敏。同樣是過日子,對生活的感悟和認知真有那么大...
    曉風拂面燕歸來閱讀 615評論 0 1
  • 第一個步驟,場景導入。比如說買東西討價還價,你覺得很便宜,他就是不肯買。這樣的場景讓用戶覺得,這事跟我有關系,才會...
    景景相依閱讀 303評論 0 2

友情鏈接更多精彩內(nèi)容