エラーメッセージが分からず困っています。
どなたか教えていただけると助かります。
下記がソースコードです。
import numpy
import soundfile
from matplotlib import pyplot
from scipy import fftpack
data,rate = soundfile.read("audio.wav")
n = len(data)
x = numpy.linspace(0, n/rate, n)
y = pyplot.figure("input")
pyplot.xlabel("time(second)")
pyplot.ylabel("amplitude")
pyplot.plot(x,y)
a = fftpack.fftfreq(n, 1/rate)
b = numpy.abs(fftpack.fft(y))
pyplot.figure("fft")
pyplot.xlabel("frequency(Hz)")
pyplot.plot(a[1:n//2], b[1:n//2])
pyplot.show()
そして実行すると下記のエラーが表示されます。
KM-S16:music administrator$ python cccc.py
Traceback (most recent call last):
File "cccc.py", line 14, in <module>
pyplot.plot(x,y)
File "/anaconda3/lib/python3.6/site-packages/matplotlib/pyplot.py", line 3358, in plot
ret = ax.plot(*args, **kwargs)
File "/anaconda3/lib/python3.6/site-packages/matplotlib/init.py", line 1855, in inner
return func(ax, *args, **kwargs)
File "/anaconda3/lib/python3.6/site-packages/matplotlib/axes/_axes.py", line 1527, in plot
for line in self._get_lines(*args, **kwargs):
File "/anaconda3/lib/python3.6/site-packages/matplotlib/axes/_base.py", line 406, in _grab_next_args
for seg in self._plot_args(this, kwargs):
File "/anaconda3/lib/python3.6/site-packages/matplotlib/axes/_base.py", line 383, in _plot_args
x, y = self._xy_from_xy(x, y)
File "/anaconda3/lib/python3.6/site-packages/matplotlib/axes/_base.py", line 242, in _xy_from_xy
"have shapes {} and {}".format(x.shape, y.shape))
ValueError: x and y must have same first dimension, but have shapes (34419,) and (1,)
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/08/27 08:26
2018/08/27 12:48