·· 维 数 ···· 阶 ········· 名 字 ········· 例 子 ············
·· 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.03.0 + 2.04.0 = 11
原文:https://www.cnblogs.com/xpwi/p/9609076.html