Matrix of vectors

I know you can declare matrix of arrays. What I want is a matrix of vectors. Is that doable? or is there a way to efficiently convert the array to vector and back efficiently?

I would settle for 2D array of vectors, like vector[N] beta[3, 3], which works for local variables. But how do I express this in a function argument? vector[][] does not work.

@bhomass, I think you have a little confusion on the types in Stan. If you haven’t gotten a chance, read through Chapter 25 in the Stan reference guide (v2.16).

There is no matrix of vectors. There are vectors, then there are arrays of vectors. There matrices, then there are arrays of matrices. A matrix is always a data structure with rows and columns and holds real values for each element. Arrays can contain any primitive data type and can have as many dimensions as needed.

I figured it out. vector[,] betas work as an argurment.

I know this is not proper use of matrix. just looking for a way I can access vectors using [row, col]. Thanks.

Just saw your edit.

If this is in your data block:

vector[N] beta[3, 3];

you can accept that in a Stan function with this type of argument:

functions {
  real foo(vector[,] beta) {
    return 0;

In functions, there’s no sizing of vector, so if that were to take a vector type and not an array of vectors, it would just be vector beta. Since you want it to take an array with 2 dimensions, you have to specify that as vector[,]. The comma there isn’t a typo.

Hope that helps.