我正在尝试在 python 中重建一首歌曲,但我无法连接相同的音符。我收到此错误:
ValueError:操作数无法与形状一起广播 (0) (1250)
这是我的代码:
import numpy as np, matplotlib.pyplot as plt
def nota(f,d):
ts = 0.0002
t = np.arange(0, d, ts)
X = 5500*np.cos(2*np.pi*f*t)
return X
# II.2.b)
pausa = nota(0,0)
La = nota(440,0.25)
Mi = nota(659.26,0.25)
Do = nota(253.25,0.25)
Sol = nota(783.99,0.25)
Si = nota(493.88,0.25)
Solbemol = nota(830.61,0.25)
def FurElise():
musica = np.array((pausa,pausa,La,Mi,La,pausa,pausa,Mi,Mi,Solbemol, \
pausa,pausa,La,Mi,La,pausa,pausa,pausa,La,Mi,La, \
pausa,pausa,Mi,Mi,Solbemol,pausa,pausa,La,Mi,La, \
pausa,Do,Sol,Do,pausa,pausa,Sol,Sol,Si,pausa,pausa, \
La,Mi,La,pausa,pausa,Mi,Mi,Mi,pausa))
y=0
for x in musica:
z=np.hstack((x,y))
y = y+x
z=np.hstack((x,y))
plt.plot(z)
plt.show()
FurElise()