美文网首页
第一次运行 TensorFlow

第一次运行 TensorFlow

作者: 暖倾心 | 来源:发表于2017-12-22 22:26 被阅读0次

$ 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

      本文链接:https://www.haomeiwen.com/subject/hyuawxtx.html