1

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'))
Mad Physicist
  • 107,652
  • 25
  • 181
  • 264
Alice
  • 588
  • 1
  • 8
  • 25
  • @JohanC I've edited my question with the definition of `t` value which is times calculated from frames. I'm not sure what you mean by one-to-one correspondence. I tried your suggestion but the errors persist. Also using `plt.plot(t, rmse_max_scaled, color='b')` and `plt.plot(t, energy_max_scaled, 'r--')` achieves the same graphs on the samples that work but 20% still throw the above error. – Alice Jan 12 '22 at 19:51
  • 1
    Your problem is that there are not enough `t` values. You need as many `t` values as corresponding `y` values. So e.g. `frames = range(len(rmse))` for the first plot. And `frames = range(len(energy_max_scaled))` for the second plot. It is a bit suspicious that `rmse_max_scaled` and `energy_max_scaled` don't have the same length. – JohanC Jan 12 '22 at 20:07
  • @JohanC thank you for clearing things up. I was able to code a solution. – Alice Jan 12 '22 at 20:24

2 Answers2

0

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'))
Alice
  • 588
  • 1
  • 8
  • 25
0

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

physics
  • 21
  • 1
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 13 '22 at 08:46