Skip to content
Prev 306829 / 398506 Next

Problem with mutli-dimensional array

Hello,

I'm glad it helped.
Now you have what is a data structure problem. The computations are the 
same but in a different output.

First of all a terminology issue. In R the correct names for the data 
structures you've refered to are 'list', 'matrix' and 'array'. To make 
it short,

vector ---> 1-dim
matrix ---> 2-dim
array ---> n-dim

and

list ---> no dim attribute, can hold any type of data structure.

Your first sentence of this last post would read (changes in uppercase)

Actually I am trying to make an LIST of length 7, where each LIST ELEMENT
  IS AN ARRAY containing a different number of 2 by 2 matrices.

In what follows, for the 3-dim array case I'll use the naming convention 
[row, column, slice].
Each of your output list elements is an array with a possibly varying 
number of slices. Right now all of them have 64 slices.

1. You need a list of 7 elements, each of them indexed by your current 'i';
2. Each of those elements is a 3-dim array, each slice is a 2x2 matrix 
and each slice is indexed by your current 'l'.
3. Let's try it.


Nx <- rep(0, length(x))
Ny <- rep(0, length(y))
n <- (x+1)*(y+1)

results <- vector("list", 7)

for(i in 1:length(x)){
     Nx[i] <- length(1:(x[i]+1))
     Ny[i] <- length(1:(y[i]+1))
     results[[i]] <- array(dim = c(2, 2, n[i]))
     l <- 1
     for(j in 1:(Nx[i])){
         for(k in 1:(Ny[i])){
             tmp <- c((0:x[i])[j], (0:y[i])[k],-(0:x[i])[j], -(0:y[i])[k])
             results[[i]][,, l] <- mat.stat[,,i] + matrix(tmp, nrow=2, 
ncol=2,byrow=T)
             l <- l + 1
         }
     }
}
results


I think this is it. Let us now if not.

Rui Barradas
Em 03-10-2012 08:48, Loukia Spineli escreveu: