An array of vectors

Viewed 77

I have an n-dimensional array of length 2 vectors.

...
vector[2] w[n];
...

Are the following equivalent, if I would like to perform the calculation $w_1 + w_2$

...
for(i in 1:n){
  Mu[i] = w[i][1] + w[i][2];
}
...

and

...
for(i in 1:n){
  Mu[i] = w[i,1] + w[i,2];
}
...
2 Answers

They are equivalent. The answer to this question can be found here: Answer link

Yes, they're the same, as JLee already noted. The other way to do this is to transpose w and use

vector[N] w_tr[2];
...
vector[N] Mu = w_tr[1] + w_tr[2];

You need vector types in order to add them.

Related