Skip to main content
 首页 » 编程设计

python之在 SciPy.IO.wavfile 中,我遇到了数据 ndim 的问题

2025年05月04日7haluo1

我有一个一维数组 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' 

我该如何解决?

谢谢。

请您参考如下方法:

您正在传递字符串 'y' 而不是变量 y 作为数据参数。

它应该像这样工作:

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