[英]ipython3 numpy array not saving
I have a Filter
object containing an array with data, and when iterrating over the object and trying to save the data.. it zeros out and nothing is getting saved. 我有一个
Filter
对象,其中包含一个包含数据的数组,并且在对该对象进行迭代并尝试保存数据时。它清零并且没有任何保存。
valid = filter(None, results)
print(results)
filenames = [x[0] for x in valid]
samples = [x[1] for x in valid]
durations = [x[2] for x in valid]
print(samples)
samples = np.asarray(samples)
np.savetxt(join(data_root, 'filenames.txt'), filenames, fmt='%s')
np.savetxt(join(data_root, 'durations.txt'), durations, fmt='%i')
%time np.save(join(data_root, 'samples.npy'), samples)
print('Saved', len(list(valid)), 'samples')
[('data/drums/samples/anywhereyougo_1.2sec.wav', array([-0.00331263, -0.00248447, 0.00124224, ..., 0. ,
-0.00207039, -0.00455487], dtype=float32), 58576), ('data/drums/samples/anywhereyougo_2.8sec.wav', array([ 0. , 0.00041356, 0. , ..., 0. ,
0.00041356, -0.00041356], dtype=float32), 136053)]
[]
CPU times: user 362 µs, sys: 205 µs, total: 567 µs
Wall time: 612 µs
Saved 0 samples
And all I get in the samples.npy
is the following : 我在
samples.npy
得到的全部如下:
**�NUMPYF{'descr': '<f8', 'fortran_order': False, 'shape': (0,), } **
I'm assuming that's an empty num py array.. just started with numpy 我假设那是一个空的num py数组..刚开始是numpy
So after looking at the original code in a non-iPython interpreter 因此,在非iPython解释器中查看原始代码之后
rearranged things : 重新安排的事情:
samples = []
filenames = []
durations = []
sample_total = 0
valid = filter(None, results)
for x in enumerate(valid):
filenames.append(x[1][0])
samples.append(x[1][1])
durations.append(x[1][2])
sample_total = x[0] + 1
samples = np.asarray(samples)
np.savetxt(join(data_root, 'filenames.txt'), filenames, fmt='%s')
np.savetxt(join(data_root, 'durations.txt'), durations, fmt='%i')
%time np.save(join(data_root, 'samples.npy'), samples)
print("Saved " + str(sample_total) + " samples")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.