我犯了这个错误,有人能帮我吗?你知道吗
TypeError: 'numpy.float64' object cannot be interpreted as an integer.
def stft(sig, frameSize, overlapFac=0.5, window=np.hanning):
win = window(frameSize)
hopSize = int(frameSize - np.floor(overlapFac * frameSize))
# zeros at beginning (thus center of 1st window should be for sample nr. 0)
samples = np.append(np.zeros(int(frameSize/2.0)), sig)
# cols for windowing
cols = np.ceil( (len(samples) - frameSize) / float(hopSize)) + 1
# zeros at end (thus samples can be fully covered by frames)
samples = np.append(samples, np.zeros(frameSize))
frames = stride_tricks.as_strided(samples, shape=(cols, frameSize),strides(samples.strides[0]*hopSize,samples.strides[0])).copy()
frames *= win
return np.fft.rfft(frames)
<ipython-input-113-e40a989a9c6b> in stft(sig, frameSize, overlapFac, window)
10 samples = np.append(samples, np.zeros(frameSize))
11
---> 12 frames = stride_tricks.as_strided(samples, shape=(cols, frameSize), strides=(samples.strides[0]*hopSize, samples.strides[0])).copy()
13 frames *= win
14
~\AppData\Roaming\Python\Python37\site-packages\numpy\lib\stride_tricks.py in as_strided(x, shape, strides, subok, writeable)
101 interface['strides'] = tuple(strides)
102
--> 103 array = np.asarray(DummyArray(interface, base=x))
104 # The route via `__interface__` does not preserve structured
105 # dtypes. Since dtype should remain unchanged, we set it explicitly.
~\AppData\Roaming\Python\Python37\site-packages\numpy\core\numeric.py in asarray(a, dtype, order)
536
537 """
--> 538 return array(a, dtype, copy=False, order=order)
539
540
TypeError: 'numpy.float64' object cannot be interpreted as an integer
我不知道问题出在哪里,我读到的是python版本的问题,但不是,我不知道怎么解决!你知道吗
最后,我找到了解决办法。谢谢!你知道吗
问题可能出在
cols
变量上。np.ceil
返回np.float64
;是的,它是一个整数值,但仍然是一个float数据类型。重读np.ceil
文档。你知道吗在
math
包中可以找到另一种方法:cols = int(cols)
也应该起作用。你知道吗相关问题 更多 >
编程相关推荐