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)]
and I use
new_array = numpy.vstack([datas])
to get the 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)]]
But I really prefer one is :
(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)
Which function should I use?
Thanks.
[]
in thevstack
call. Just try:new_array = numpy.vstack(datas)
. – ely Oct 8 '13 at 17:45[]
, but I got a error message "ValueError: all the input array dimensions except for the concatenation axis must match exactly.
" – user2858910 Oct 8 '13 at 18:05datas[0].shape
? – ely Oct 8 '13 at 18:12datas[0].shape
, it's(1308662,)
, and I printdatas[1].shape
, it's(1306358,)
. – user2858910 Oct 8 '13 at 18:26