This is an old version, view current version.

8 Mixed Operations

These functions perform conversions between Stan containers matrix, vector, row vector and arrays.

matrix to_matrix(matrix m)
Return the matrix m itself.
Available since 2.3

matrix to_matrix(vector v)
Convert the column vector v to a size(v) by 1 matrix.
Available since 2.3

matrix to_matrix(row_vector v)
Convert the row vector v to a 1 by size(v) matrix.
Available since 2.3

matrix to_matrix(matrix m, int m, int n)
Convert a matrix m to a matrix with m rows and n columns filled in column-major order.
Available since 2.15

matrix to_matrix(vector v, int m, int n)
Convert a vector v to a matrix with m rows and n columns filled in column-major order.
Available since 2.15

matrix to_matrix(row_vector v, int m, int n)
Convert a row_vector a to a matrix with m rows and n columns filled in column-major order.
Available since 2.15

matrix to_matrix(matrix m, int m, int n, int col_major)
Convert a matrix m to a matrix with m rows and n columns filled in row-major order if col_major equals 0 (otherwise, they get filled in column-major order).
Available since 2.15

matrix to_matrix(vector v, int m, int n, int col_major)
Convert a vector v to a matrix with m rows and n columns filled in row-major order if col_major equals 0 (otherwise, they get filled in column-major order).
Available since 2.15

matrix to_matrix(row_vector v, int m, int n, int col_major)
Convert a row_vector a to a matrix with m rows and n columns filled in row-major order if col_major equals 0 (otherwise, they get filled in column-major order).
Available since 2.15

matrix to_matrix(array[] real a, int m, int n)
Convert a one-dimensional array a to a matrix with m rows and n columns filled in column-major order.
Available since 2.15

matrix to_matrix(array[] int a, int m, int n)
Convert a one-dimensional array a to a matrix with m rows and n columns filled in column-major order.
Available since 2.15

matrix to_matrix(array[] real a, int m, int n, int col_major)
Convert a one-dimensional array a to a matrix with m rows and n columns filled in row-major order if col_major equals 0 (otherwise, they get filled in column-major order).
Available since 2.15

matrix to_matrix(array[] int a, int m, int n, int col_major)
Convert a one-dimensional array a to a matrix with m rows and n columns filled in row-major order if col_major equals 0 (otherwise, they get filled in column-major order).
Available since 2.15

matrix to_matrix(array[,] real a)
Convert the two dimensional array a to a matrix with the same dimensions and indexing order.
Available since 2.3

matrix to_matrix(array[,] int a)
Convert the two dimensional array a to a matrix with the same dimensions and indexing order. If any of the dimensions of a are zero, the result will be a \(0 \times 0\) matrix.
Available since 2.3

vector to_vector(matrix m)
Convert the matrix m to a column vector in column-major order.
Available since 2.0

vector to_vector(vector v)
Return the column vector v itself.
Available since 2.3

vector to_vector(row_vector v)
Convert the row vector v to a column vector.
Available since 2.3

vector to_vector(array[] real a)
Convert the one-dimensional array a to a column vector.
Available since 2.3

vector to_vector(array[] int a)
Convert the one-dimensional integer array a to a column vector.
Available since 2.3

row_vector to_row_vector(matrix m)
Convert the matrix m to a row vector in column-major order.
Available since 2.3

row_vector to_row_vector(vector v)
Convert the column vector v to a row vector.
Available since 2.3

row_vector to_row_vector(row_vector v)
Return the row vector v itself.
Available since 2.3

row_vector to_row_vector(array[] real a)
Convert the one-dimensional array a to a row vector.
Available since 2.3

row_vector to_row_vector(array[] int a)
Convert the one-dimensional array a to a row vector.
Available since 2.3

array[,] real to_array_2d(matrix m)
Convert the matrix m to a two dimensional array with the same dimensions and indexing order.
Available since 2.3

array[] real to_array_1d(vector v)
Convert the column vector v to a one-dimensional array.
Available since 2.3

array[] real to_array_1d(row_vector v)
Convert the row vector v to a one-dimensional array.
Available since 2.3

array[] real to_array_1d(matrix m)
Convert the matrix m to a one-dimensional array in column-major order.
Available since 2.3

array[] real to_array_1d(array[...] real a)
Convert the array a (of any dimension up to 10) to a one-dimensional array in row-major order.
Available since 2.3

array[] int to_array_1d(array[...] int a)
Convert the array a (of any dimension up to 10) to a one-dimensional array in row-major order.
Available since 2.3