【ERROR】InvalidArgumentError: cannot compute Pack as input #2(zero-based)......

错误信息

在tensorflow堆叠张量的时候报错:InvalidArgumentError: cannot compute Pack as input #2(zero-based) was expected to be a float tensor but is a int32 tensor [Op:Pack] name: stack

import tensorflow as tf
x1 = tf.constant([137.97, 104.50, 100.00, 124.32, 79.20, 99.00, 124.00, 114.00, 106.69, 138.05, 53.75, 46.91, 68.00, 63.02, 81.26, 86.21])
x2 = tf.constant([3, 2, 2 ,3, 1, 2, 3, 2, 2, 3, 1, 1, 1, 1, 2, 2])
y = tf.constant([145.00, 110.00, 93.00, 116.00, 65.32, 104.00, 118.00, 91.00, 62.00, 133.00, 51.00, 45.00, 78.50, 69.65, 75.69, 95.30])
x0 = tf.ones(len(x1))
X = tf.stack([x0, x1, x2])

在这里插入图片描述
在这里插入图片描述

解决方法

原因很简单,就是堆叠的类型需要一致,因为没学过基础,直接上手的,所以都在报错中学习基础了。加上一句把x2转成float32类型就行了:

x2 = tf.cast(x2, dtype=tf.float32)

在这里插入图片描述

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值