An array is a comma-separated, ordered collection of elements. In this shot, we'll learn how to concatenate arrays using Julia.
We can concatenate arrays in Julia using the following functions.
vcat
: This concatenates along dimension 1
.hcat
: This concatenates along dimension 2
.hcat(pass comma separated arrays) vcat(pass comma separated arrays)
Both the functions will take arrays as parameters.
Both the functions will return a new array after concatenation.
a = [1 2 3 4 5] b = [6 7 8 9 10; 11 12 13 14 15] println("Displaying vcat concatenation") #concatenation along dimension 1 display(vcat(a,b)) c = [1; 2; 3; 4; 5] d = [6 7; 8 9; 10 11; 12 13; 14 15] println("\nDisplaying hcat concatenation") #concatenation along dimension 2 display(hcat(c,d))
a
and b
.a
and b
along the dimension 1
using the vcat
function and display the returned new array.c
and d
.c
and d
along the dimension 2
using the hcat
function and display the returned new array.RELATED TAGS
CONTRIBUTOR
View all Courses