python-3.x - 'float' 对象不能被解释为整数 python
问题描述
我正在关注 Keras 中的数据生成器教程:
https://stanford.edu/~shervine/blog/keras-how-to-generate-data-on-the-fly
在 __data_generation 函数中,他们创建了一个空的 numpy 数组 X。但是,当我这样做时,我收到以下错误:
TypeError:'float' 对象不能解释为整数
我输入的维度是 (1,7000,208) 和 (1,7000)。但是,当我尝试制作 numpy 数组时,我得到了我之前提到的错误。这就是我所做的:
dim_snp = (1,7000,208)
dim_pos = (1,7000)
X_snp = np.empty([1,dim_snp,1])
X_pos = np.empty((1,dim_pos))
有人可以解释为什么我会收到这个错误吗?
解决方案
In [23]: dim_snp = (1,7000,208)
In [24]: (1, dim_snp, 1)
Out[24]: (1, (1, 7000, 208), 1)
In [25]: np.zeros((1, dim_snp, 1))
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-25-10a1e967522d> in <module>
----> 1 np.zeros((1, dim_snp, 1))
TypeError: 'tuple' object cannot be interpreted as an integer
In [26]: np.zeros((1, 1, 700, 208, 1)).shape
Out[26]: (1, 1, 700, 208, 1)
推荐阅读
- amazon-web-services - AWSLambdaClient 调用给出异常:com.amazonaws.SdkClientException:无法执行 HTTP 请求:目标服务器未能响应
- azure - 从本地网络连接到 Azure SQL
- r - 如何从代码块中的数据框中获取数字(或文本)到 RMarkdown html 输出中的文本?
- python - 嵌套字典键作为变量
- css - Primeng/CSS 用于固定列和可滚动列
- c# - 通过 Web API 发布 KnowledgeArticle
- bit-manipulation - 翻转所有位长(在java中)
- javascript - plotBands Highcharts,如果我增加 pointInterval 数据显示不匹配
- html - 使用 Flex 在文本上方右对齐徽标
- javascript - 带有 jquery.localize 的语言翻译器