类型错误:传递给参数“a”的值的数据类型不在允许值列表中

2024-10-01 04:55:26 发布

您现在位置:Python中文网/ 问答频道 /正文

我有以下代码:

_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。有什么问题吗?


Tags: to代码convertvaluetf错误npmatrix
1条回答
网友
1楼 · 发布于 2024-10-01 04:55:26

对tf.matmul的输入只接受这些数据类型:

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

将X和Y的数据类型更改为上述数据类型有效。

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))

相关问题 更多 >