连接2个Julia数组而不修改它们 [英] Concatenate 2 Julia Arrays without modifying them
本文介绍了连接2个Julia数组而不修改它们的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想连接2个数组.
julia> l1=["a","b"]
2-element Array{ASCIIString,1}:
"a"
"b"
julia> l2=["c","d"]
2-element Array{ASCIIString,1}:
"c"
"d"
append!
可以执行此操作,但是此功能正在修改l1
(该功能以!
命名)
append!
can do this but this function is modifying l1
(that's a function named with a !
)
julia> append!(l1, l2)
4-element Array{ASCIIString,1}:
"a"
"b"
"c"
"d"
julia> l1
4-element Array{ASCIIString,1}:
"a"
"b"
"c"
"d"
我正在寻找append
函数(没有感叹号).
I was looking for a append
function (without exclamation point).
但是似乎不存在这样的功能.
But such a function doesn't seems to exist.
有什么主意吗?
推荐答案
除了@oleeinar的答案,您还可以使用hcat
和vcat
连接数组:
In addition to @oleeinar's answer, you can use hcat
and vcat
to concatenate arrays:
l3 = vcat(l1, l2)
4-element Array{ASCIIString,1}:
"a"
"b"
"c"
"d"
您还可以将hcat
水平连接:
l4 = hcat(l1, l2)
2x2 Array{ASCIIString,2}:
"a" "c"
"b" "d"
这篇关于连接2个Julia数组而不修改它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文