python - 数据类型 float32 for attr 'T' 不在允许值列表中 : int32, int64

标签 python python-3.x tensorflow

我已经考虑过这两篇文章( thisthis ),但它们不是我的问题和解决方案。我有以下代码在 tf 中创建前馈网络:

step = 500
fromState = 0
toState = 5000000
numOfState = (toState - fromState) / step
numOfAction = 11

tf.reset_default_graph()
inputs1 = tf.placeholder(shape=[1,numOfState], dtype = tf.float32)
W = tf.Variable(tf.random_uniform([numOfState,4],0,0.01),)
Qout = tf.matmul(inputs1,W)
predict = tf.argmax(Qout,1)

但是,我在这一行中遇到以下错误 Qout = tf.matmul(inputs1,W) :

TypeError: DataType float32 for attr 'T' not in list of allowed values: int32, int64



显然一切正常,但问题是这个错误是什么以及它来自哪里?

最佳答案

我找到了问题所在。问题来自numOfState .我发现它的类型是 float32 .因此,通过将此变量转换为 int 来解决问题:

#numOfState = (toState - fromState) / step 
# change to
numOfState = int((toState - fromState) / step)

关于python - 数据类型 float32 for attr 'T' 不在允许值列表中 : int32, int64,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47004522/

相关文章:

python - 将嵌套列表转换为 Pandas DF

python - 在 python 中使用 rabbitmq 时出现 "pika.exceptions.ConnectionClosed"错误

python-3.x - Openpyxl创建带有表格的excel文件导致需要恢复错误的文件

python-3.x - 如何使用 nibabel 修改 mgh/dicom/nifti 文件的方向

python-3.x - 输入 0 与图层 flatten_5 : expected min_ndim=3, 发现 ndim=2 不兼容

Python 3.6.3 : Multiple "Exception ignored in: <generator object..." in flask app

python - 错误返回链表中 'm' 位置节点的值

python-3.x - Wav 音频电平太大

tensorflow - 使用 JointDistributionSequential 的 Tensorflow 概率层次模型

python - 如何在 CNTK Sequential 中添加两层