一个简单的命令 -- "np.save",也许我误解了

a simple command -- "np.save", maybe i misunderstood

只是完成 numpy.save 的示例 -- http://docs.scipy.org/doc/numpy/reference/generated/numpy.save.html

例子

from tempfile import TemporaryFile

outfile = TemporaryFile()

x = np.arange(10)

np.save(outfile, x)

执行此命令(突出显示)后,为什么我在当前目录中找不到名为 "outfile" 的输出文件?抱歉,这听起来可能很愚蠢

outfile.seek(0) # Only needed here to simulate closing & reopening file

np.load(outfile)

array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])

这是因为您正在使用 - TemporaryFile ,它是一个临时文件,不会作为 outfile 存储在您的目录中。

如果您想将其保存到 outfile ,您可以将其作为名称,它会将其保存到该文件。

np.save('outfile',x)

像这样保存以加载时,您将需要再次使用 , 文件名作为字符串 -

np.load('outfile')