简体   繁体   中英

ValueError: x and y must have same first dimension, but have shapes (165,) and (166,)

I'm looping through a list of audio filenames, loading them, calculating the STE and RMSE, and then plotting said values. However, the occasional error message is thrown for about 20% of the files.

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,)

So on and so forth.

I took a look at this question and I believe the problem may be similar as I am also using square brackets in my call to plt.plot on line 2 of the code below. However, changing this to parentheses throws a syntax error. I also find it strange that only 20% of >1000 samples are affected and that the shape seems to be incremented by 1.

Is this a metadata issue? What exactly could be causing this problem?

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'))

The issue as pointed out by @JohanC is that there were not enough t values as the corresponding y values. Reformatting the code as follows solved the problem.

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'))

This is because x and y are the same length and there are not enough values of t.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM