我只是举个例子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])
这是因为您使用的是-
TemporaryFile
,这是一个临时文件,在您的目录中不作为outfile
存储。你知道吗如果你想把它保存到
outfile
,你可以给它命名,它会把它保存到那个文件中。你知道吗当这样保存以加载时,您需要再次使用文件名作为字符串-
相关问题 更多 >
编程相关推荐