在SciPy.IO.wavfile中我的数据ndim出现问题

2 投票
1 回答
1241 浏览
提问于 2025-04-17 09:48

我有一个一维数组y,里面有132300个数据。

print y.ndim 

这个代码给我返回了1。

现在,当我使用 write('440saw2000.wav', '44100', 'y') 时,我收到了以下错误信息:

Traceback (most recent call last):
File "C:\Users\Matt\The Mathematics Of Digital Synthesizers\Scripts\filter.py", line 47, in <module>
write('440saw2000.wav', '44100', 'y')
File "C:\Python27\lib\site-packages\scipy\io\wavfile.py", line 161, in write
if data.ndim == 1:
AttributeError: 'str' object has no attribute 'ndim'

我该怎么解决这个问题呢?

谢谢。

1 个回答

1

你传递的是字符串'y',而不是变量y作为数据参数。

应该这样写:

write('440saw2000.wav', 44100, y) # without quotes around y and 44100

撰写回答