版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/yangfengling1023/article/details/82353487
1)使用图来表示计算任务
2)在被称之为会话的上下文中执行图
3)使用tensor表示数据
4)通过变量维护状态
5)使用feed和fetch可以为任意的操作赋值或者从其中获取数据
tensoflow是一个编程系统,使用图表示计算任务,图中的节点称之为op,一个op获得0个或多个tensor,执行计算,产生0个或多个tensor,tensor看作是一个n维的数组或列表,图必须在会话里被启动
#coding:utf-8
import tensorflow as tf
##tensorflow的程序代码
##定义常量
m1 = tf.constant([[3,3]]) ##1X2
m2 = tf.constant([[2],[3]]) ##2X1
##创建一个矩阵乘法,把m1、m2传入
product = tf.matmul(m1,m2)
print(product) ##输出的结果为Tensor("MatMul:0", shape=(1, 1), dtype=int32)
##定义一个会话,启动默认的图
sess = tf.Session()
##调用sess的run方法来执行矩阵乘法
result = sess.run(product)
print(result)
输出的结果为:[[15]]
sess.close()
##使用with时不需要执行会话的关闭,当程序执行完之后,会自动进行关闭
with tf.Session() as sess:
result = sess.run(product)
print(result)
输出的结果为:[[15]]