简体   繁体   English

ValueError: x 和 y 必须具有相同的第一个维度,但具有形状 (99955,) 和 (15000,)

[英]ValueError: x and y must have same first dimension, but have shapes (99955,) and (15000,)

So I am trying to plot my.wav file using matplotlib.所以我正在尝试使用 matplotlib 来 plot my.wav 文件。 This is my list of code这是我的代码列表

from scipy.io import wavfile
import numpy as np
import matplotlib.pyplot as plt

train_audio_path = 'input/train2/audio/'
filename = 'bu/uji-bu-051.wav'
sample_rate, samples = wavfile.read(train_audio_path + filename)

fig = plt.figure(figsize=(14, 8))
ax1 = fig.add_subplot(211)
ax1.set_title('Raw wave of ' + filename)
ax1.set_ylabel('Amplitude')
ax1.plot(np.linspace(0, sample_rate/len(samples), sample_rate), samples)

But I kept facing with this kind of error that say my x and y don't have same first dimension.但我一直面临这种错误,说我的 x 和 y 没有相同的第一维。

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-62-94bfcd54ac3d> in <module>
      5 ax1.set_title('Raw wave of ' + filename)
      6 ax1.set_ylabel('Amplitude')
----> 7 ax1.plot(np.linspace(0, sample_rate/len(samples), sample_rate), samples)
      8 
      9 # ax2 = fig.add_subplot(212)

~\.conda\envs\speechRecog\lib\site-packages\matplotlib\axes\_axes.py in plot(self, scalex, scaley, data, *args, **kwargs)
   1741         """
   1742         kwargs = cbook.normalize_kwargs(kwargs, mlines.Line2D)
-> 1743         lines = [*self._get_lines(*args, data=data, **kwargs)]
   1744         for line in lines:
   1745             self.add_line(line)

~\.conda\envs\speechRecog\lib\site-packages\matplotlib\axes\_base.py in __call__(self, data, *args, **kwargs)
    271                 this += args[0],
    272                 args = args[1:]
--> 273             yield from self._plot_args(this, kwargs)
    274 
    275     def get_next_color(self):

~\.conda\envs\speechRecog\lib\site-packages\matplotlib\axes\_base.py in _plot_args(self, tup, kwargs)
    397 
    398         if x.shape[0] != y.shape[0]:
--> 399             raise ValueError(f"x and y must have same first dimension, but "
    400                              f"have shapes {x.shape} and {y.shape}")
    401         if x.ndim > 2 or y.ndim > 2:

ValueError: x and y must have same first dimension, but have shapes (99955,) and (15000,)

What should I do?我应该怎么办?

Use np.arange insted of linspace got to know from here!使用 np.arange insted 的 linspace 从这里开始了解! by doing this it matches the both shape of x and y cordinates in plot通过这样做,它匹配 plot 中 x 和 y 坐标的形状

from scipy.io import wavfile
import numpy as np
import matplotlib.pyplot as plt    

train_audio_path = 'input/train2/audio/'
filename = 'bu/uji-bu-051.wav'
sample_rate, samples = wavfile.read(train_audio_path + filename)
 
fig = plt.figure(figsize=(14, 8))
ax1 = fig.add_subplot(211)
ax1.set_title('Raw wave of ' + filename)
ax1.set_ylabel('Amplitude')
ax1.plot(np.arange(0, len(samples)/sample_rate, 1/sample_rate),samples)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ValueError:x 和 y 必须具有相同的第一维,但具有形状 (6,) 和 (8,) - ValueError: x and y must have same first dimension, but have shapes (6,) and (8,) ValueError:x 和 y 必须具有相同的第一维,但具有形状 (1, 2) 和 (2,) - ValueError: x and y must have same first dimension, but have shapes (1, 2) and (2,) ValueError:x 和 y 必须具有相同的第一维,但具有形状 - ValueError: x and y must have same first dimension, but have shapes 线性回归模型形状 - ValueError:x 和 y 必须具有相同的第一维,但具有形状 (5,) 和 (1, 5) - Linear regression model shapes - ValueError: x and y must have same first dimension, but have shapes (5,) and (1, 5) ValueError: x 和 y 必须具有相同的第一维,但具有形状 (10, 1) 和 (90,) - ValueError: x and y must have same first dimension, but have shapes (10, 1) and (90,) 线性回归:ValueError:x 和 y 必须具有相同的第一维,但具有形状 (10, 1) 和 (1, 1) - Linear Regression : ValueError: x and y must have same first dimension, but have shapes (10, 1) and (1, 1) ValueError:x 和 y 必须具有相同的第一维,但具有形状 (165,) 和 (166,) - ValueError: x and y must have same first dimension, but have shapes (165,) and (166,) Matplotlib 中的 Plot K-Means:ValueError:x 和 y 必须具有相同的第一个维度,但具有形状 (10,) 和 (1,) - Plot K-Means in Matplotlib: ValueError: x and y must have same first dimension, but have shapes (10,) and (1,) ValueError:x 和 y 必须具有相同的第一维,但具有形状 (512,) 和 (256,) - ValueError: x and y must have same first dimension, but have shapes (512,) and (256,) ValueError:x和y必须具有相同的第一尺寸,但形状为(4200,)和(16800,1) - ValueError: x and y must have same first dimension, but have shapes (4200,) and (16800, 1)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM