今天学tensorflow的时候惊奇的发现,tf也可以实现矩阵乘法
接下来分别用tf 和 np来实现矩阵乘法
- Tensorflow
import tensorflow as tf
A = tf.constant([[1,2],[3,4]])
B = tf.constant([[5,6],[7,8]])
C = tf.matmul(A,B)
print(C)
返回值:
tf.Tensor(
[[19 22]
[43 50]], shape=(2, 2), dtype=int32)
2.Numpy
import numpy as np
a = np.array([[1,2],[3,4]])
b = np.array([[5,6],[7,8]])
c = np.dot(a,b)
print(c)
返回值:
[[19 22]
[43 50]]
成功实现矩阵相乘!