TensorFlow笔记-03-张量,计算图,会话

TensorFlow笔记-03-张量,计算图,会话

  • 搭建你的第一个神经网络,总结搭建八股
  • 基于TensorFlow的NN:用张量表示数据,用计算图搭建神经网络,用会话执行计算图,优化线上的权重(参数),得到模型
  • 张量(tensor):多维数组(列表)
  • 阶:张量的维数

···维数······阶 ··········名字············例子·············
···0-D········0·······标量 scalar·····s=1 2 3
···1-D········0·······向量 vector·····s=[1,2,3]
···2-D········0·······矩阵 matrix·····s=[ [1,2,3], [4,5,6],[7,8,9] ]
···n-D········0·······标量 tensor·····s=[[[[[….n个

# 两个张量的加法
import  tensorflow as tf

a = tf.constant([1.0, 2.0])
b = tf.constant([3.0, 4.0])

result = a+b
print(result)
# 两个张量的加法
import  tensorflow as tf

# x 是一个一行两列的张量
x = tf.constant([[1.0, 2.0]])
# x 是一个两行一列的张量
w = tf.constant([[3.0], [4.0]])

'''
构建计算图,但不运算
y = XW
 = x1*w1 + x2*w2
'''
# 矩阵相乘
y = tf.matmul(x, w)
print(y)

运行结果

Tensor(“MatMul:0”, shape=(1, 1), dtype=float32)

# 两个张量的加法
import  tensorflow as tf

# x 是一个一行两列的张量
x = tf.constant([[1.0, 2.0]])
# x 是一个两行一列的张量
w = tf.constant([[3.0], [4.0]])

'''
构建计算图,但不运算
y = XW
 = x1*w1 + x2*w2
'''
# 矩阵相乘
y = tf.matmul(x, w)
print(y)

# 会话:执行节点运算
with tf.Session() as sess:
    print(sess.run(y))

运行结果

y = 1.0*3.0 + 2.0*4.0 = 11
这里写图片描述
拜拜


- 本笔记不允许任何个人和组织转载

猜你喜欢

转载自blog.csdn.net/qq_40147863/article/details/81875693