ValueError: x and y must have same first dimension, but have shapes (2140699,) and (4281398,)
ValueError: x and y must have same first dimension, but have shapes (2140699,) and (4281398,)
我使用 miniconda jupyter notebook python 并且我正在尝试实现一台机器(音频过滤)。我收到这个错误,我真的不知道如何解决它。
这里我用文件路径导入了我需要的库:
import wave as we
import numpy as np
import matplotlib.pyplot as plt
dir = r'/home/pc/Downloads/Bubble audios'
这里是绘制图形的函数:
def read_wav(wavfile, plots=True, normal=False):
f = wavfile
params = f.getparams()
# print(params)
nchannels, sampwidth, framerate, nframes = params[:4]
strData = f.readframes(nframes) # , string format
waveData = np.frombuffer(strData, dtype=np.int16) # Convert a string to an int
# wave amplitude normalization
if normal == True:
waveData = waveData*1.0/(max(abs(waveData)))
#
if plots == True:
time = np.arange(0, nframes ,dtype=np.int16) *(1.0 / framerate)
plt.figure(dpi=100)
plt.plot(time, waveData)
plt.xlabel("Time")
plt.ylabel("Amplitude")
plt.title("Single channel wavedata")
plt.show()
return (Wave, time)
def fft_wav(waveData, plots=True):
f_array = np.fft.fft(waveData) # Fourier transform, the result is a complex array
f_abs = f_array
axis_f = np.linspace(0, 250, np.int(len(f_array)/2)) # map to 250
# axis_f = np.linspace(0, 250, np.int(len(f_array))) # map to 250
if plots == True:
plt.figure(dpi=100)
plt.plot(axis_f, np.abs(f_abs[0:len(axis_f)]))
# plt.plot(axis_f, np.abs(f_abs))
plt.xlabel("Frequency")
plt.ylabel("Amplitude spectrum")
plt.title("Tile map")
plt.show()
return f_abs
在这里我用我想要读取和绘制的文件调用函数。
f = we.open(dir+r'/Ars1_Aufnahme.wav', 'rb')
Wave, time = read_wav(f)
我得到的错误:
ValueError: x and y must have same first dimension, but have shapes (2140699,) and (4281398,)
我尝试使用 np.reshape 但它没有用,或者我可能用错了。那么,有什么建议吗?
看来你的时间是你波浪大小的1/2。也许您的 nframe
太短了。如果你这样做 nframses = 2*nframes
错误是什么?
我使用 miniconda jupyter notebook python 并且我正在尝试实现一台机器(音频过滤)。我收到这个错误,我真的不知道如何解决它。
这里我用文件路径导入了我需要的库:
import wave as we
import numpy as np
import matplotlib.pyplot as plt
dir = r'/home/pc/Downloads/Bubble audios'
这里是绘制图形的函数:
def read_wav(wavfile, plots=True, normal=False):
f = wavfile
params = f.getparams()
# print(params)
nchannels, sampwidth, framerate, nframes = params[:4]
strData = f.readframes(nframes) # , string format
waveData = np.frombuffer(strData, dtype=np.int16) # Convert a string to an int
# wave amplitude normalization
if normal == True:
waveData = waveData*1.0/(max(abs(waveData)))
#
if plots == True:
time = np.arange(0, nframes ,dtype=np.int16) *(1.0 / framerate)
plt.figure(dpi=100)
plt.plot(time, waveData)
plt.xlabel("Time")
plt.ylabel("Amplitude")
plt.title("Single channel wavedata")
plt.show()
return (Wave, time)
def fft_wav(waveData, plots=True):
f_array = np.fft.fft(waveData) # Fourier transform, the result is a complex array
f_abs = f_array
axis_f = np.linspace(0, 250, np.int(len(f_array)/2)) # map to 250
# axis_f = np.linspace(0, 250, np.int(len(f_array))) # map to 250
if plots == True:
plt.figure(dpi=100)
plt.plot(axis_f, np.abs(f_abs[0:len(axis_f)]))
# plt.plot(axis_f, np.abs(f_abs))
plt.xlabel("Frequency")
plt.ylabel("Amplitude spectrum")
plt.title("Tile map")
plt.show()
return f_abs
在这里我用我想要读取和绘制的文件调用函数。
f = we.open(dir+r'/Ars1_Aufnahme.wav', 'rb')
Wave, time = read_wav(f)
我得到的错误:
ValueError: x and y must have same first dimension, but have shapes (2140699,) and (4281398,)
我尝试使用 np.reshape 但它没有用,或者我可能用错了。那么,有什么建议吗?
看来你的时间是你波浪大小的1/2。也许您的 nframe
太短了。如果你这样做 nframses = 2*nframes
错误是什么?