相关疑难解决方法(0)

读入朱莉娅的数组

我对Julia相对较新,我正在寻找一种有效的方式从文本文件读入并将每个"列"存储在一个数组中(我有2列,但一般解决方案也会很棒).例如,我想要输入

    1 2
    3 4
    5 6
Run Code Online (Sandbox Code Playgroud)

被读入两个数组,比如x和y,这样x = [1 3 5]和y = [2 4 6].我有一个工作的解决方案(可能不会编译,只是自由交配),但我觉得有一种更有效的方法来做到这一点,而不是hcat和逐行读取输入文件.任何建议都非常感谢!

目前,我或多或少地做了以下事情:

x=[]; 
y=[]; 
f=open("filename"); 
f=readlines(f); 
for str in f 
     s1, s2= split(str, " "); 
     s1=int(s1); 
     s2=int(s2); 
     x=hcat(x, s1); 
     y=hcat(y, s2);
end
Run Code Online (Sandbox Code Playgroud)

arrays input julia

11
推荐指数
1
解决办法
2989
查看次数

标签 统计

arrays ×1

input ×1

julia ×1