在Julia中将插值函数保存到单独的文件中
在Julia/Python中,将数组保存为文件(例如.txt/.csv格式)很容易,但是有没有办法保存插值数组生成的函数?举个简单的例子:在Julia中将插值函数保存到单独的文件中,julia,interpolation,Julia,Interpolation,在Julia/Python中,将数组保存为文件(例如.txt/.csv格式)很容易,但是有没有办法保存插值数组生成的函数?举个简单的例子: using Interpolations inter = Dict("constant" => BSpline(Constant()), "linear" => BSpline(Linear()), "quadratic" => BSpline(Quadratic(Line(OnCell()))), "cubi
using Interpolations
inter = Dict("constant" => BSpline(Constant()),
"linear" => BSpline(Linear()),
"quadratic" => BSpline(Quadratic(Line(OnCell()))),
"cubic" => BSpline(Cubic(Line(OnCell())))
)
arr = rand(100, 100, 100) # 3D array
func = interpolate(arr, inter["cubic"])
如何保存此函数以备将来使用,从而在每次运行程序时不需要再次插值函数?一个简单的解决方案是使用 然后重新加载
using Interpolations, JLD2
@load "savedfunction.jld"
func
我尝试了完全相同的语法,但当我加载函数并调用它时,它给了我大量的警告,像
…(type)这样的东西在工作区中不存在;重建└ @ JLD2 C:\Users\User\.julia\packages\JLD2\w2vgv\src\data.jl:11581
,然后出现一个错误MethodError:Array{Symbol,1}类型的对象不可调用。使用方括号[]对数组进行索引。
在@load
之前是否使用插值?否则,将重建与插值函数的内存布局匹配的类型,但其行为不同。我已经更正了示例代码。
using Interpolations, JLD2
@load "savedfunction.jld"
func