TensorFlow矩阵向量运算

1 向量点乘
结果是一个向量在另一个向量方向上投影的长度,是一个标量。
2 向量叉乘
结果是一个和已有两个向量都垂直的向量。
向量a = (x1,y1),b = (x2,y2)
a *b = x1*x2+y1*y2 =|a||b|cos
a叉乘b = x1 * y2 - x2 * y1=|a||b|sin
tensorflow
3. 矩阵乘
tf.matmul(a,b)//matrix_multiply== tf.tensordot(a,b,axie=1)
tf.tensordot()
功能:同numpy.tensordot,根据axis计算点乘。
输入:axes=1或axes=[[1],[0]],即为矩阵乘。

tf.multiply(a,b) == a * b
tf.mul()是可以b’roadcast,
(3,2) * (2) = (3,2)*(1,2) = (3,2)
(3,2)*(3,1) = (3,2)

矩阵点成向量
(3,2) .* (2)
u=tf.reshape(np.arange(0,5),[3,2])
v=tf.Variable(tf.random_uniform([2]))
mul=tf.reduce_sum(tf.mul(tf.cast(u,tf.float32),v),reduction_indices=1)
s=tf.Session()
s.run(tf.initialize_all_variables())
print s.run(mul)

你可能感兴趣的:(TensorFlow矩阵向量运算)