Concatenation of arrays in Julia language
This example demonstrates various ways to combine arrays in the Julia programming language.
Introduction
Array concatenation is used to combine two or more arrays into one. This can be useful in data processing when it is necessary to combine the results of various calculations or collect data from different sources. In the Julia language, there are several ways to perform this operation, both by creating a new array and by modifying an existing one.
The main part
Vertical concatenation
Creating two one-dimensional arrays
a = [1,2,3]
b = [4,5,6]
Combining arrays vertically (one under the other)
There are two ways to do this.:
Method 1: Using semicolon syntax
ab = [a;b]
Method 2: using the function vcat (vertical concatenation)
ab = vcat(a,b)
Horizontal concatenation
For horizontal integration (next to each other), we use hcat
ab = hcat(a,b)  # Результат: матрица 3×2
# 1  4
# 2  5
# 3  6
Mutating concatenation (changing the original array)
Function append! modifies the first array by adding elements of the second one to it
append!(a,b)  # Теперь a стало [1,2,3,4,5,6]
# При этом оригинальный массив b остается без изменений
Conclusion
In this example, we looked at the various methods of concatenating arrays in Julia. We've learned how to combine arrays both vertically (vcat), and horizontally (hcat), and also studied the mutating operation append!, which modifies the original array. These methods are useful when working with data, when you need to combine the results of different calculations or collect information from multiple sources into a single array.
The example was developed using materials from Rosetta Code