$ 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替劈,可以設(shè)定其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.]