我有一个import copy
original = [[1]]
a = original[:]
b = list(original)
c = copy.copy(original)
original[0][0] = 2
print(a) # [[2]]
print(b) # [[2]]
print(c) # [[2]]
对象,其中包含一个包含数据的数组,当它在对象上进行迭代并尝试保存数据时...它会清零并且没有任何内容被保存。
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
的内容如下:
samples.npy
我假设这是一个空的num py数组..刚开始使用numpy
答案 0 :(得分:0)
所以在查看非iPython解释器中的原始代码后
重新安排的事情:
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")