# vec

vec(Array) -> Vector

Vectorize an array using column-major convention.

## Examples

In the Julia programming language, the function `vec(array)` is used to vectorize an array using column-major convention.

``````julia> arr = [1 2 3; 4 5 6; 7 8 9]
3×3 Array{Int64,2}:
1  2  3
4  5  6
7  8  9

julia> vec(arr)
9-element Array{Int64,1}:
1
4
7
2
5
8
3
6
9``````

This function reshapes the array into a one-dimensional vector by stacking the columns of the array in a column-major order.

Common usage examples:

1. Vectorize a 2D array:

``````julia> arr = [1 2; 3 4; 5 6];
julia> vec(arr)
6-element Array{Int64,1}:
1
3
5
2
4
6``````

The `vec` function transforms the 2D array into a 1D vector by stacking the columns.

2. Vectorize a 3D array:
``````julia> arr = [1 2 3; 4 5 6; 7 8 9] |> reshape(_, (3, 3, 1));
julia> vec(arr)
9-element Array{Int64,1}:
1
4
7
2
5
8
3
6
9``````

The `vec` function transforms the 3D array into a 1D vector by stacking the columns.

Common mistake example:

``````julia> arr = [1 2 3; 4 5 6];
julia> vec(arr)
ERROR: DimensionMismatch("matrix is not square: dimensions are (2, 3)")``````

In this example, the input array is not a square matrix, resulting in a `DimensionMismatch` error. Make sure the input array has appropriate dimensions for vectorization using `vec`.