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

标签 python io scipy waveform

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

关于python - 在 SciPy.IO.wavfile 中,我遇到了数据 ndim 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8780126/

相关文章:

python - 读/写文本文件

java - 反序列化如何定位SerialVersionUid

c++从二进制文件中读取整数,缺少一些数据

python - 如何获取 Pandas 数据框中一行的百分位数?

Python:联合上的交集

python - python中的多元曲线拟合用于估计椭圆形状的参数和阶数

python - numpy 向量化 : check if strings in array end with strings in another array

python - 为相似名词创建空间知识库

python - 如何防止for循环停止?

python - 在 Python 虚拟机中创建一种新语言