Filling a matrix with multivariate normal

Dear all,

I am trying to fill a matrix, whose rows corresponds to independent multivariate normal random variables. I have tried to following:

data {
      int<lower=1> J;    
      int<lower =1> K;  
      vector[K] mu_a;    // mean vector of a
  matrix[J,K] a;
    to_vector(a) ~ normal(mu_a, rep_vector(5.0, K));
stan_data <- list(J = 2, 
                    K = 8,
                     mu_a = c(log(1.4e6), log(6.66e-11), log(6),log(5), log(1e4), log(3.7),log(4e4),log(1e-4)),
fit_model <- stan("model_code.stan",          
                  data = stan_data,
                  chains = 1, iter = 1000,

I am getting the following error:

Chain 1: Unrecoverable error evaluating the log probability at the initial value.
Chain 1: Exception: normal_lpdf: Location parameter has dimension = 8, expecting dimension = 16; a function was called with arguments of different scalar, array, vector, or matrix types, and they were not consistently sized;  all arguments must be scalars or multidimensional values of the same shape.

How do I overcome this error?
Am I correct to say that the code in the model block fills each row of matrix a with independent multivariate normal random vector?

please help.


to_vector flattens the matrix to an array.

Just do:

for(j in 1:J) {
  a[j,] ~ normal(mu_a, 5.0);