Assign values to an array or vector, and specifying fixed vectors/matrices

I keep running into situations, where I want to assign values to an array or vector in a convenient short-hand way. I somehow do not seem to find any description on how this can be done (if it is possible). There are at least two variants of this question.

For example, is there a more elegant way of assigning the following (the last line is only there to illustrate why I might do this)?

int tmpindx[4];
tmpindx[1] = 1;
tmpindx[2] = 2;
tmpindx[3] = 4;
tmpindx[4] = 5;
logp[3] = log1m_exp(log_sum_exp(logp[tmpindx]));
E.g. is there some syntax like
tmpindx = (1, 2, 4, 5);
?
I realized that I also keep running into situations, where I want to specify array or vector or matrix constants such as in:
Lambda ~ multi_normal_cholesky( (0 0 0), (1 0 0, 0 1 0, 0 0 1) );
or the like, where some kind of syntax that does not force me to first define a vector and a matrix in the transformed data block.

real x[3] = {1, 2, 3};
vector[3] y = [1, 2, 3];
matrix[3, 3] z = [[1, 2, 3],
                  [4, 5, 6],
                  [7, 8, 9]]
3 Likes

Not quite. The vectors are intrinsically row vectors, so you need to transpose to get a vector:

vector[3] y = [1, 2, 3]';
row_vector[3] y_t = [1, 2, 3];

The upshot is that the matrix syntax build a matrix out of multiple row vectors, not out of multiple vectors.

4 Likes