簡體   English   中英

ValueError:x 和 y 必須具有相同的第一維,但具有形狀 (165,) 和 (166,)

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM