执行如下语句报错 TypeError: Input ‘b’ of ‘MatMul’ Op has type float32 that does not match type int32 of argument ‘a’.
X_in = tf.matmul(X,weights[‘in’])+biases[‘in’]
在使用tf.matmul()时提示两个参量一个为float32型,另外一个为float32型
解决方法:转换成同类型。
矩阵乘前进行X类型转换X=tf.cast(X,tf.float32)
变为
X=tf.cast(X,tf.float32)
X_in = tf.matmul(X,weights[‘in’])+biases[‘in’]
本文详细解析了在使用TensorFlow进行矩阵运算时遇到的类型错误问题,具体表现为tf.matmul()函数输入参数类型不匹配导致的TypeError。文章提供了有效的解决方案,即通过tf.cast()函数将输入矩阵统一转换为相同的数据类型,以确保运算的正确执行。
745

被折叠的 条评论
为什么被折叠?



