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