Tensorflow框架搭建神经网络
一、张量、计算图、会话
1. 张量
多维数组(列表) 阶:张量的维数
维数 | 阶 | 名字 | 例子 |
---|---|---|---|
0-D | 0 | 标量 scalar | s=1 2 3 |
1-D | 1 | 向量 vector | v=[1,2,3] |
2-D | 2 | 矩阵 matrix | m=[[1,2,3],[4,5,6],[7,8,9]] |
n-D | n | 张量 tensor | t=[[[… (n个) |
张量可以表示0阶到n阶数组(列表)
2.计算图
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", shanpe=(2, ), dtype=float32)
计算图(Graph):搭建神经网络的计算过程,只搭建,不运算。
y = X W = x 1 ∗ w 1 + x 2 ∗ w 2 y=XW=x_1*w_1+x_2*w_2 y=XW=x1∗w1+x2∗w