ipython3 numpy数组未保存
我有一个ipython3 numpy数组未保存,python,arrays,numpy,Python,Arrays,Numpy,我有一个过滤器对象,它包含一个包含数据的数组,当我在对象上排列并试图保存数据时。。它归零,没有任何东西被保存 笔记本代码 在Jupyter笔记本中运行时的输出 我在示例中得到的所有信息。npy如下所示: **�NUMPYF{'descr': '<f8', 'fortran_order': False, 'shape': (0,), } ** **�NUMPYF{'descr':'在非iPython解释器中查看原始代码后 重新安排的事情: samples = [] f
过滤器
对象,它包含一个包含数据的数组,当我在对象上排列并试图保存数据时。。它归零,没有任何东西被保存
笔记本代码
在Jupyter笔记本中运行时的输出
我在示例中得到的所有信息。npy
如下所示:
**�NUMPYF{'descr': '<f8', 'fortran_order': False, 'shape': (0,), } **
**�NUMPYF{'descr':'在非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")
看起来像是print(samples)
(第二次打印)显示了[]
。所以没有任何东西通过samples=[…]
expression。在担心要保存什么之前,请确保生成了有效的samples
数组。您的过滤器
对象看起来不起作用。请查看由savetxt
命令生成的文本文件。由np.save
生成的npy
不是人类可读的。您应该用np.load
命令来读取它。@hpaulj当然。但是文本文件看起来像一个空数组。它不可能在该行中存储数据samples.npy
对吗?我想还有其他方法可以访问筛选对象的数组吗?@hpaulji如果文本看起来是空的,它就是空的。您用0个元素。您是否检查了有效的或示例的形状
或长度
(保存前)?我认为问题不在于保存
。问题在于过滤器
。如果这仍然令人困惑,请练习保存已知形状的简单数组,例如np.arange(10),np.one((3,6))
等。
**�NUMPYF{'descr': '<f8', 'fortran_order': False, 'shape': (0,), } **
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")