2017-06-07 37 views
4

我有以下代碼:類型錯誤:傳遞參數值「」具有數據類型不是在允許值的列表

_X = np.arange(1, 7).reshape((2, 3)) 
_Y = np.arange(1, 7).reshape((3, 2)) 

X = tf.convert_to_tensor(_X) 
Y = tf.convert_to_tensor(_Y) 

# Matrix multiplication 
out1 = tf.matmul(X, Y) 

對於它,我得到這個錯誤:

TypeError: Value passed to parameter 'a' has DataType int64 not in list of allowed values: float16, float32, float64, int32, complex64, complex128 

我我正在使用最新版本的Tensorflow。可能是什麼問題?

+1

的可能的複製[不能做tensorflow矩陣乘法(https://stackoverflow.com/questions/44414905/cant-do-matrix-multiplication-with-tensorflow) – Engineero

回答

4

輸入到tf.matmul只接受這些dtypes:

a: Tensor of type float16, float32, float64, int32, complex64, complex128 and rank > 1. 

D型X和Y的改變上述dtypes作品。

import tensorflow as tf 
import numpy as np 
_X = np.arange(1, 7).reshape((2, 3)) 
_Y = np.arange(1, 7).reshape((3, 2)) 

X = tf.convert_to_tensor(_X,dtype=tf.int32) 
Y = tf.convert_to_tensor(_Y,dtype=tf.int32) 

# Matrix multiplication 
out1 = tf.matmul(X, Y) 

sess = tf.Session() 
print(sess.run(out1)) 
相關問題