如何在Julia中保存文件

如何在Julia中保存文件

本文介绍了如何在Julia中保存文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在某些时候(我认为是Julia v0.7),您可以执行@save savepath thingtosave以便使用Julia来保存文件.我尝试在v0.7上运行此命令,以查看是否收到弃用警告,但即使在0.7上,它也表示未定义@save.

At some point, (I think Julia v0.7) you could do @save savepath thingtosave in order to save files using Julia. I tried to run this on v0.7 to see if I got a deprecation warning but even on 0.7 it says that @save is undefined.

如何使用Julia以编程方式保存文件?

How can I programmatically save files using Julia?

推荐答案

自从您提到@save以来,大概是在使用 JLD.jl 或其后续版本 JLD2.jl .

Since you mention @save, presumably, you were using JLD.jl or its successor JLD2.jl.

使用JLD2的简单示例是

A simple example for using JLD2 would be

julia> using JLD2

julia> @save "test.jld2" x

julia> x = nothing # "forgetting" x

julia> @load "test.jld2"
1-element Array{Symbol,1}:
 :x

julia> x
2×2 Array{Float64,2}:
 0.698264  0.319665
 0.252174  0.80799

write相比,这些软件包基于 HDF5 (通过 HDF5.jl ).它们几乎允许您存储任意Julia对象. HDF5(不一定是JLD/JLD2)是一种几乎所有编程语言和许多程序(例如Mathematica)都支持的文件格式.与read/write可能会在将来的Julia版本中更改的read/write相比,它适合长期存储.

In contrast to write, those packages are based on HDF5 (through HDF5.jl). They pretty much allow you to store arbitrary Julia objects. HDF5 (not necessarily JLD/JLD2) is a file format which is supported by almost all programming languages and many programs (Mathematica for example). It is suitable for long-term storage in contrast to read/write which might change in future Julia versions.

请注意,由于它是软件包功能,而不是Base(或stdlib)的一部分,因此不会在0.7中显示.

Note that this doesn't show up in 0.7 since it is a package feature and not part of Base (or a stdlib).

这篇关于如何在Julia中保存文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 18:31