TensorFlow框架--张量,计算图和会话

搭建第一个神经网络,总结搭建八股python

https://blog.csdn.net/pandamax/article/details/63684633

关于对张量的理解数组

基于Tensorflow的NN(神经网络):

  1. 张量表示数据
  2. 计算图搭建神经网络
  3. 会话执行计算图,并优化线上的权重(参数)
  4. 获得模型

张量(tensor):多维数组(列表) 阶:张量的维数

维数      阶        名字                  例子网络

0-D        0       标量scalar          s=1,2,3优化

1-D        1       向量vector          v=[1,2,3].net

2-D        2       矩阵matrix          m=[[1,2,3],[4,5,6],[7,8,9]]scala

n-D        n       张量tensor          t=[[[...--多少个【,多少个ncode

              张量表示0阶到n阶数组(列表)blog

数据类型:tf.float32 tf.int32 ...

import get

import tensorflow as tf
a=tf.constant([1.0,2.0]) #定义常量为一维数组:一行一列--一种大类被有两种元素
b=tf.constant([3.0,4.0])
result=a+b
print result

显示:Tensor(“add:0”,shape=(2,),dtype=float32)it

add:0--节点名:第0个输出 shape:维度 (2,)一维数组长度为2 dtype:数据类型

计算图(Graph):搭建神经网络的计算过程,只搭建,不运算。

import tensorflow as tf
x=tf.constant([[1.0,2.0]])
#定义常量为一行两列的二维数组
w=tf.constant([[3.0],[4.0]])
#定义常量为两行一列的二维数组
y=tf.matmul(x,w)
#矩阵相乘运算
print(y)

 显示:Tensor("matmul:0",shape(1,1),dtype=float32)   

    会话(Session):执行计算图的节点运算

with tf.Session() as sess:print sess.run(y)

import tensorflow as tf

x=tf.constant([[1.0,2.0]])
w=tf.constant([[3.0],[4.0]])

y=tf.matmul(x,w) 

with tf.Session() as sess:
     print sess.run(y)

结果:

[[11.]]---一行一列的二维数组