【E-10】object of type <class 'float'> cannot be safely interpreted as an integer.(numpy)

错误提示位置

freqs = np.linspace(0, sample_rate/2, nfft/2 + 1)

   

可能原因

1numpy版本问题

2Python版本问题:在python2,/只留下了整数部分,去掉了小数,是int型。而在python3里,/的结果是真正意义上的除法,结果是float型。所以便出现了Error Message: 'float' object cannot be interpreted as an integer。

   

解决方法

1、numpy 1.18.2 -> numpy 1.17.0

2、修改符号:freqs = np.linspace(0, sample_rate/2, nfft//2 + 1)

   

本次采用2解决

原文地址:https://www.cnblogs.com/yifanrensheng/p/13460540.html