Skip to content

Array

Create

Action Code Details
Declare 1D array of length N
real a[N];
Declare 1D array with zeros
real a[N] = rep_array(0, N);
Declare 1D array with values
real a[] = {1, 2, 5}
Declare 2D array of size N by M
real a[N,M];
Declare 2D array with values
int b[2, 3] = { { 1, 2, 3 }, { 4, 5, 6 } };
Declare 3D array of size N by M by O
real a[N,M,O];

Properties

Action Code Details
Dimensions
dims(a)
Size of first dimension
size(a)
real a[4,3]; then size(a) = 4
Number of elements
num_elements(a)

Derive

Grow

Action Code Details
Append array
append_array(x, y)

Convert

Action Code Details
To 1D array
to_array_1d(a)
To 2D array
to_array_2d(a)
To vector
to_vector(a)
To matrix
to_matrix(a)
1D array to matrix of size (column-major order)
to_matrix(a, nrow, ncol)