Can't Do Matrix Multiplication With Tensorflow
In Tensorflow, I would like to do matrix multiplication using this code: _X = np.array([[1, 2, 3], [4, 5, 6]]) _Y = np.array([[1, 1], [2, 2], [3, 3]]) X = tf.convert_to_tensor(_X)
Solution 1:
Here is the docs for tf.matmul
:
Both matrices must be of the same type. The supported types are:
float16
,float32
,float64
,int32
,complex64
,complex128
.
Changing the data type to one of the supported eliminates the error.
_X = np.array([[1, 2, 3], [4, 5, 6]], dtype=np.int32)
_Y = np.array([[1, 1], [2, 2], [3, 3]], dtype=np.int32)
X = tf.convert_to_tensor(_X)
Y = tf.convert_to_tensor(_Y)
res = tf.matmul(X, Y)
sess = tf.Session()
res.eval(session=sess)
#array([[14, 14],
# [32, 32]], dtype=int32)
Post a Comment for "Can't Do Matrix Multiplication With Tensorflow"