[英]ValueError: x and y must have same first dimension, but have shapes (6,) and (8,)
[英]ValueError: x and y must have same first dimension, but have shapes (165,) and (166,)
我正在遍歷音頻文件名列表,加載它們,計算 STE 和 RMSE,然后繪制所述值。 但是,大約 20% 的文件會偶爾出現錯誤消息。
ValueError: x and y must have same first dimension, but have shapes (165,) and (166,)
ValueError: x and y must have same first dimension, but have shapes (240,) and (241,)
等等等等。
我看了一下這個問題,我相信問題可能很相似,因為我在下面代碼的第 2 行對plt.plot
的調用中也使用了方括號。 但是,將其更改為括號會引發語法錯誤。 我還覺得奇怪的是,>1000 個樣本中只有 20% 受到影響,並且形狀似乎增加了 1。
這是元數據問題嗎? 究竟是什么導致了這個問題?
frames = range(len(energy))
t = librosa.frames_to_time(frames, sr=SAMPLE_RATE, hop_length=HOP_LENGTH)
plt.figure(figsize=(15, 5))
plt.plot(t[:len(rmse)], rmse_max_scaled, color='b')
plt.plot(t, energy_max_scaled, 'r--')
librosa.display.waveplot(sample, sr=SAMPLE_RATE, alpha=0.4)
plt.legend(('RMSE', 'Energy'))
@JohanC 指出的問題是沒有足夠的t
值作為相應的y
值。 重新格式化代碼如下解決了這個問題。
plt.figure(figsize=(15, 5))
frames = range(len(rmse))
t = librosa.frames_to_time(frames, sr=SAMPLE_RATE, hop_length=HOP_LENGTH)
plt.plot(t[:len(rmse)], rmse_max_scaled, color='b')
frames = range(len(energy))
t = librosa.frames_to_time(frames, sr=SAMPLE_RATE, hop_length=HOP_LENGTH)
plt.plot(t[:len(energy)], energy_max_scaled, 'r--')
librosa.display.waveplot(sample, sr=SAMPLE_RATE, alpha=0.4)
plt.legend(('RMSE', 'Energy'))
這是因為 x 和 y 的長度相同,並且沒有足夠的 t 值。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.