矩阵相乘
c = tf.matmul(a,b)
shape = [2,3,4] 则张量的阶为3
张量为 [2,3,4] ,则它的shape 为[3], 阶为1
相乘的两个矩阵 阶要相等
g2 = tf.Graph()
with g2.as_default():
x = tf.constant([8,1,6,5,2,3], shape=[2,3])
y = tf.constant([8,1,6], shape=[3,1])
c = tf.matmul(x, y)
with tf.Session(graph=g2) as session:
print(session.run(c))
x,y 阶相等 且 x,y的最后两维可以理解为 相乘运算维
前面的维度可以理解为 拼接的维度 必须一一对应且相等
即x.shape= […, int1,6]
则 y.shape =[…, 6,int2]
相乘结果 的shape为:
c.shape = […, int1, int2]
矩阵相加
a + b
a,b的张量 矩阵一定要相容
相容即
两张量shape 同维度有1或相等则满足相容
维度不等 相加时,高维度shape保持
低维度在相容的情况下,广播运算