“简单的命令”np.保存“,也许我误解了

2024-05-11 03:29:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我只是举个例子numpy.保存--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])

Tags: orgnumpyhttp示例docsdocsavehtml
1条回答
网友
1楼 · 发布于 2024-05-11 03:29:15

这是因为您使用的是-TemporaryFile,这是一个临时文件,在您的目录中不作为outfile存储。你知道吗

如果你想把它保存到outfile,你可以给它命名,它会把它保存到那个文件中。你知道吗

np.save('outfile',x)

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

np.load('outfile')

相关问题 更多 >