Vector vs real array


I was wondering if there is any benefit to using an array (real y[n];) over a vector (vector[n] y;).
As far as I can see the only benefit of arrays is that you can declare an integer array but not an integer vector and thus save space. But if I am working with real numbers, do I just use vectors?

With vectors I am able to vectorize (hah!) a lot more for example
price ~ normal(beta_0 + beta_1 * temp, sigma2)
is only possible when price and temp are vectors but I would have to use an explicit loop when they are arrays.
Am I overlooking something?


One dimensional real arrays are basically a less useful version of a vector.

1 Like

And what about multi-dimensional arrays vs multi-dimensional vectors (ie matrices) then? Doesn’t the same logic apply?

I only see uses if you want to have integer arrays (one or multi-dim.).

Arrays that are not just real numbers have their uses. If you want to extract “by row” it executes slightly faster to extract the first dimension of a two-dimensional array than a row of a matrix due to the way that the numbers are stored in memory.

Ah okay. Thanks!

Well, then for now I guess I can safely ignore it.

There’s a chapter in the manual discussing the distinctions and efficiency tradeoffs of arrays and matrix/vector.

Ah yes I’ve read through that now. Thank you!

To make sure I understand, is this saying real a[N] is a less useful version of vector[N] a?

In most situations, yes. The real array is less efficient to work with, many indexing and arithmetic operations will be slower

1 Like