第一次运行 TensorFlow

$ python                                                             //打开python终端

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

>>> hello = tf.constant('Hello, TensorFlow!')     // 创建一个常量 hello 

>>> sess = tf.Session()                                     //创建一个会话(Session)

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

Hello, TensorFlow!

>>> a = tf.constant(10)                                        // 创建一个常量 a

>>> b = tf.constant(32)                                        // 创建一个常量 b

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

42

>>>


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

       创建一个常量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.]

你可能感兴趣的:(第一次运行 TensorFlow)