from scipy.io.wavfile import read
filepath = glob.glob('*.wav')
rates = []
datas = []
for fp in filepath:
rate, data = read(fp)
rates.append(rate)
datas.append(data)
I get a list 'datas' which is :
[array([0, 0, 0, ..., 0, 0, 0], dtype=int16), array([0, 0, 0, ..., 0, 0, 1], dtype=int16), array([0, 0, 0, ..., 0, 0, 0], dtype=int16),..., array([0, 0, 0, ..., 0, 0, 0], dtype=int16)]
我使用
new_array = numpy.vstack([datas])
获得 new_array:
[[array([0, 0, 0, ..., 0, 0, 0], dtype=int16)
array([0, 0, 0, ..., 0, 0, 1], dtype=int16)
array([0, 0, 0, ..., 0, 0, 0], dtype=int16)
...
array([0, 0, 0, ..., 0, 0, 0], dtype=int16)]]
但我更喜欢的是:
(array([[ 0, 0, 0, ..., 0, 0, 0],
[ 0, 0, 0, ..., 0, 0, 1],
[ 0, 0, 0, ..., 0, 0, 0],
...,
[ 0, 0, 0, ..., 0, 0, 0]], dtype=int16)
我应该使用哪个函数?
谢谢。
vstack
调用中您不需要额外的[]
。只需尝试:new_array = numpy.vstack(datas)
。 - ely[]
,但是我收到了一个错误信息:“ValueError: all the input array dimensions except for the concatenation axis must match exactly.
” - user2858910