【问题标题】:'float' object cannot be interpreted as an integer python'float' 对象不能解释为整数 python
【发布时间】:2019-11-01 15:54:11
【问题描述】:

我正在关注 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))

谁能解释我为什么会收到这个错误?

【问题讨论】:

  • np.empty 的参数应该是一个数字元组。 (1, dim_pos) 是什么?
  • 它甚至没有走到那一行。错误来自 X_snp?在教程中,dim 是 32,32,32
  • 你不能将我的评论应用到X_snp 行吗?
  • 这是我的 numpy 数组的大小。这是一个大小为 7000 x 208 的矩阵
  • 我没有问(1, dim_pos) 是什么意思!我想让你检查一下它实际上是什么,并确定它是否适合工作。

标签: python-3.x numpy


【解决方案1】:
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)

【讨论】:

    猜你喜欢
    • 2016-01-26
    • 1970-01-01
    • 2018-03-19
    • 2018-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多