Hi listers,
I am having some trouble in a matrix multiplication...
I have already checked some posts, but I didn't find my problem...
I have the following code...
But I am not getting the right multiplication...
I checked the dimension and they are fine...
id_y <- array(1:10,dim=c(2,1,5))
id_yt<-
MarcioRibeiro wrote:
>
> Hi listers,
> I am having some trouble in a matrix multiplication...
> I have already checked some posts, but I didn't find my problem...
> I have the following code...
> But I am not getting the right multiplication...
> I checked the dimension and they are fine...
>
I think your problem is with R's behavior of dropping array indices
when dim==1.
Simulating that
> m1 <- matrix(1:2,nrow=2)
> m2 <- matrix(1:2,ncol=2)
> m1 %*% m2
[,1] [,2]
[1,]12
[2,]24
> m1[,] %*% m2[,]
[,1]
[1,]5
[1,]5
> m1[,,drop=FALSE] %*% m2[,,drop=
Hi again...
I will get an array with 5 matrix 2x2, with dimension 2x2x5
This code below works fine... And I am applying the same procedure...
The problem might be when I do the permutation of the array, but I checked
the dimension and its all right...
array1 <- array(1:30,dim=c(3,2,5))
array2 <-
MarcioRibeiro wrote:
Hi listers,
I am having some trouble in a matrix multiplication...
I have already checked some posts, but I didn't find my problem...
I have the following code...
But I am not getting the right multiplication...
I checked the dimension and they are fine...
id_y <- array(1:
Hi again,
I understood what you guys explained...
But, there isn't a way to do a multiplication of matrix with a FOR command
or otherelse where one o my dimension is ONE...
Well, as my data file is small, I did the procedure at the excel... But,
this is not the good procedure...
Thanks,
Marcio
U
You need to put in calls to 'as.matrix'. It's
a bit tricky though -- what you want depends
on whether it is the first or second subscript
that has length 1.
as.matrix(id_y[,,i])
if the second dimension has length 1.
t(as.matrix(id_y[,,i]))
if the first dimension has length 1.
Patrick Burns
I think this works in general, although it's
a little bit clunky:
id_y <- array(1:10,dim=c(2,1,5))
id_yt <- aperm(id_y,c(2,1,3))
m_id <- array(dim=c(dim(id_y)[1],dim(id_y)[1],dim(id_y)[3]))
for (i in 1:dim(id_y)[3]){
m1 <- array(id_y[,,i],dim=dim(id_y)[1:2])
m2 <- array(id_yt[,,i],dim=di
8 matches
Mail list logo