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
The hvcat() is an inbuilt function in julia which is used to concatenate the given arrays horizontally and vertically in one call. The first parameter specifies the number of arguments to concatenate in each block row.
Using '*' operator It is used to concatenate different strings and/or characters into a single string. We can concatenate two or more strings in Julia using * operator.
A Vector in Julia can be created with the use of a pre-defined keyword Vector() or by simply writing Vector elements within square brackets([]). There are different ways of creating Vector. vector_name = [value1, value2, value3,..] or vector_name = Vector{Datatype}([value1, value2, value3,..])
Use the vcat
and hcat
functions:
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With