TypeError:传递给参数'a'的值使DataType不在允许值列表中(TypeError: Value passed to parameter 'a' h

系统教程 行业动态 更新时间:2024-06-14 16:53:13
TypeError:传递给参数'a'的值使DataType不在允许值列表中(TypeError: Value passed to parameter 'a' has DataType not in list of allowed values)

我有以下代码:

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

I have the following code:

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

For it, I am getting this error:

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

I am using the latest version of Tensorflow. What could be the issue?

最满意答案

输入到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))

Inputs to tf.matmul accepts only these dtypes :

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

Changing dtype of X and Y to above dtypes works.

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

更多推荐

本文发布于:2023-04-06 01:39:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/a9e027b5e575b9a668f206227a639a26.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:参数   列表中   DataType   TypeError   passed

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!