1、矩阵乘法
import tensorflow as tf
import numpy as np
x = np.arange(0, 4, 1, float)
x = np.reshape(x, [2, 2])
print(x)
f = tf.matmul(x, x,transpose_a=False, transpose_b=False)
sess = tf.Session()
print(sess.run(f))
输出x
[[ 0. 1.]
[ 2. 3.]]
输出f
[[ 2. 3.]
[ 6. 11.]]
2、矩阵对应元素相乘
import tensorflow as tf
import numpy as np
x = np.arange(0, 4, 1, float)
x = np.reshape(x, [2, 2])
print(x)
f = tf.multiply(x, x)
sess = tf.Session()
print(sess.run(f))
输出x
[[ 0. 1.]
[ 2. 3.]]
输出f
[[ 0. 1.]
[ 4. 9.]]