import tensorflow as tf
import numpy as np
x=tf.constant([[1,2,3],[1,2,3],[1,2,3]])
y=tf.constant([[2,1,1],[2,1,1],[2,1,1]])
x1=([[1,2,3],[1,2,3],[1,2,3]])
y1=([[2,1,1],[2,1,1],[2,1,1]])
z=tf.multiply(x,y)
z1=tf.matmul(x,y)
z2 = np.dot(x1,y1)
print('dot\n',z2)
z3 = np.multiply(x1,y1)
print('np.multiply\n',z3)
with tf.Session() as sess:
print('tf.multiply\n',sess.run(z))
print('tf.matmul\n',sess.run(z1))
print(sess.run(np.dot(x,y)))
'''
之前使用sess.run(np.dot(x,y))输出结果为点乘结果,直接计算np.dot(x1,y1)结果为矩阵乘法.
tf.matmul() 为矩阵乘法
tf.multiply() 为矩阵点乘
np.dot() 为矩阵乘法
np.multiply() 为矩阵点乘
=============== 输出结果 ===============
np.dot
[[12 6 6]
[12 6 6]
[12 6 6]]
np.multiply
[[2 2 3]
[2 2 3]
[2 2 3]]
tf.multiply
[[2 2 3]
[2 2 3]
[2 2 3]]
tf.matmul
[[12 6 6]
[12 6 6]
[12 6 6]]
'''