微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

python – TypeError:传递给参数’a’的值使DataType不在允许值列表中

我有以下代码

_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.可能是什么问题?

解决方法:

输入到tf.matmul只接受这些dtypes:

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

将X和Y的dtype更改为上面的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))

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐