在 Julia 中连接数组 [英] Concatenating arrays in Julia
本文介绍了在 Julia 中连接数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果两个 Int
数组是,a = [1;2;3]
和 b = [4;5;6]
,我们如何在两个维度上连接两个数组?预期的输出是,
If the two Int
arrays are, a = [1;2;3]
and b = [4;5;6]
, how do we concatenate the two arrays in both the dimensions? The expected outputs are,
julia> out1
6-element Array{Int64,1}:
1
2
3
4
5
6
julia> out2
3x2 Array{Int64,2}:
1 4
2 5
3 6
推荐答案
使用 vcat
和 hcat
函数:
julia> a, b = [1;2;3], [4;5;6]
([1,2,3],[4,5,6])
help?> vcat
Base.vcat(A...)
Concatenate along dimension 1
julia> vcat(a, b)
6-element Array{Int64,1}:
1
2
3
4
5
6
help?> hcat
Base.hcat(A...)
Concatenate along dimension 2
julia> hcat(a, b)
3x2 Array{Int64,2}:
1 4
2 5
3 6
这篇关于在 Julia 中连接数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文