TypeError: object of type <class ‘float‘> cannot be safely interpreted as an integer.
程序员文章站
2022-04-26 08:13:36
...
今天在跑语音频谱图的代码的时候出现了下面的错误:
Traceback (most recent call last):
File "/Users/admin/anaconda3/lib/python3.7/site-packages/numpy/core/function_base.py", line 117, in linspace
num = operator.index(num)
TypeError: 'float' object cannot be interpreted as an integer
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "spectrogram.py", line 14, in <module>
freqs = np.linspace(0, sampling_rate/2, fft_size/2+1)
File "<__array_function__ internals>", line 6, in linspace
File "/Users/admin/anaconda3/lib/python3.7/site-packages/numpy/core/function_base.py", line 121, in linspace
.format(type(num)))
TypeError: object of type <class 'float'> cannot be safely interpreted as an integer.
解决方法
freqs = np.linspace(0, sampling_rate/2, fft_size//2+1)
把第三个参数变成int类型就行了,我这里加了一个斜杠。
参考文献
【E-10】object of type <class ‘float’> cannot be safely interpreted as an integer.(numpy)
上一篇: iOS UIButton之UIEdgeInsets详解
下一篇: php数组的数据结构
推荐阅读
-
TypeError: object of type <class ‘float‘> cannot be safely interpreted as an integer.
-
windows下 TypeError: 'numpy.float64' object cannot be interpreted as an index 的解决方案
-
frcnn系列错误: TypeError: 'numpy.float64' object cannot be interpreted as an index 的解决方案
-
错误TypeError: object of type <class ‘numpy.float64‘> cannot be safely interpreted as an integer.解决方案