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<-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]){
m_id[,,i]<-id_y[,,i]%*%id_yt[,,i]
}
m_id
--
View this message in context:
http://www.nabble.com/Matrix-multiplication---code-problem-tp22835003p22835003.html
Sent from the R help mailing list archive at Nabble.com.
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: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]){ > m_id[,,i]<-id_y[,,i]%*%id_yt[,,i] > } > m_id > >What did you expect to happen? Ben Bolker -- View this message in context: http://www.nabble.com/Matrix-multiplication---code-problem-tp22835003p22835082.html Sent from the R help mailing list archive at Nabble.com.
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: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]){ > m_id[,,i]<-id_y[,,i]%*%id_yt[,,i] > } > m_id > >Due to indexing, you are loosing dimensions. The problem is that you expect to *loose exactly one* dimension in this case (hence drop = FALSE won't be of help right away). Hence it might be a good idea to know what you are going to have exactly at the end (as in- and output). Uwe Ligges