在Julia中保存和检索字典的正确方法是什么? [英] What is the correct way to save and retrieve dictionaries in Julia?

查看:328
本文介绍了在Julia中保存和检索字典的正确方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到,朱莉娅正确地解释了在其中有结构的MAT文件,这些文件是没有问题地读作字典的。现在我已经创建了一个我自己的字典,它具有以下结构:

 (String,String)=> [Int,Int,Int] 

我可以用 writeddlm 来保存它,它会生成一个非常有序的
表格文本文件,由制表符分隔( \ t ),但是如果不进行大量的解析,我就无法检索它。如果我使用 readdlm ,我得到一个Any类型的数组,每行的结构非常不舒适。

 (\Bla bla \,\tururu\)[a,b,c]
''和等符号的两列字符串, '['

解决方案

您可以使用 JLD HDF5 (Julia Data)子模块> 包:

 使用HDF5,JLD $ b $ Pkg.add(HDF5)
bd = Dict(
(a,b)=> [1,2,3],
(c,d)=> [4,5,6 ],
(e,f)=> [7,8,9]

save(data.jld,data,d)
load(data.jld)[data]




JLD模块的优势在于它保留了每个变量的精确类型信息。


lockquote>

I have seen that Julia adecuately interprets "MAT" files which have structures in them which are read as dictionaries without problem. Now I have created a dictionary of my own, which has the following structure

(String, String)=> [ Int, Int, Int]

on each entry. I can save it with writeddlm and it produces a very orderly tabular text file, separated by tabs (\t), but then I cannot retrieve it without doing a LOT of parsing. If I use readdlm I get an array of type Any, with the very unconfortable structure at each line

"(\"Bla bla\", \"tururu\")"     "[a, b, c]"

That is, two columns of Strings which contain signs such as '"' and '['.

解决方案

You could use the JLD (Julia Data) submodule included in the HDF5 package:

Pkg.add("HDF5")
using HDF5, JLD
d = Dict(
    ("a", "b") => [1, 2, 3],
    ("c", "d") => [4, 5, 6],
    ("e", "f") => [7, 8, 9]
)
save("data.jld", "data", d)
load("data.jld")["data"]

the advantage of the JLD module is that it preserves the exact type information of each variable.

这篇关于在Julia中保存和检索字典的正确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆