本文使用的是linux版本的Anaconda环境
#创建名为 tensorflow的环境,设置python版本为3.5
conda create -n tensorflow python=3.5
#进入 tensorflow环境
source activate tensorflow
#安装一些安装包
conda install pandas matplotlib jupyter notebook scipy scikit-learn
conda install -c conda-forge tensorflow
tensorflow中的数据都是以tensor对象的形式存储的
tf.constant()
返回的 tensor 是一个常量 tensor,因为这个 tensor 的值不会变。
# 可以是0维 A = tf.constant(1234) # 可以是1维 B = tf.constant([123,456,789]) # 可以是2维 C = tf.constant([ [123,456,789], [222,333,444] ]) #可以是字符串 hello_constant = tf.constant('Hello World!')
tf.Session
创建了一个 sess
的 session 实例。然后 sess.run()
函数对 tensor 求值,并返回结果。
with tf.Session() as sess:
output = sess.run(hello_constant)
给tensor对象进行传参数
tf.placeholder()用这个方法给传个类型