Hi all,
I am doing a array marginalization over one dimension in the following
manner:
==========================================================for(l in 1:L)
{
flst=list(Pzu, Pzi, array(Puzu[,as.character(r[[l,"u"]])],
dim=dim(Puzu)[1], dimnames=dimnames(Puzu)[1]), array(Pizi[,as.character(r[[l,
"i"]])], dim=dim(Pizi)[1], dimnames=dimnames(Pizi)[1]) );
tempa = 1;
for(j in 1:length(flst)) tempa = tempa %X% flst[[j]];
tempPzu = apply(tempa, 1, sum);
tPzu = tPzu + tempPzu;
tPuzu[,as.character(r[[l,"u"]])] =
tPuzu[,as.character(r[[l,"u"]])] +
tempPzu;
tempPzi = apply(tempa, 2, sum);
tPzi = tPzi + tempPzi;
tPizi[,as.character(r[[l,"i"]])] =
tPizi[,as.character(r[[l,"i"]])] +
tempPzi;
for(j in 1:ncomp) tPrjzuzilst[[j]][,,r[[l,rbase+j]]]
tPrjzuzilst[[j]][,,r[[l,rbase+j]]] + tempa;
}
==========================================================My question involves
the operation using tempPzu and tempPzi. Is my use of
loop in this case to addup certain arrays together, too .. dumb? Is there
another way of doing such things by vectorization?
Thanks in advance,
Nachiketa
[[alternative HTML version deleted]]
Hi all,
The previous post had some html formatting and did not go through. So,
here it is again in plain text.
I am doing a array marginalization over one dimension in the following manner:
==========================================================for(l in 1:L)
{
flst=list(Pzu, Pzi, array(Puzu[,as.character(r[[l,"u"]])],
dim=dim(Puzu)[1], dimnames=dimnames(Puzu)[1]),
array(Pizi[,as.character(r[[l, "i"]])], dim=dim(Pizi)[1],
dimnames=dimnames(Pizi)[1]) );
tempa = 1;
for(j in 1:length(flst)) tempa = tempa %X% flst[[j]];
tempPzu = apply(tempa, 1, sum);
tPzu = tPzu + tempPzu;
tPuzu[,as.character(r[[l,"u"]])] = tPuzu[,as.character
(r[[l,"u"]])] + tempPzu;
tempPzi = apply(tempa, 2, sum);
tPzi = tPzi + tempPzi;
tPizi[,as.character(r[[l,"i"]])]
tPizi[,as.character(r[[l,"i"]])] + tempPzi;
for(j in 1:ncomp) tPrjzuzilst[[j]][,,r[[l,rbase+j]]]
tPrjzuzilst[[j]][,,r[[l,rbase+j]]] + tempa;
}
==========================================================My question involves
the operation using tempPzu and tempPzi. Is my
use of loop in this case to addup certain arrays together, too ..
dumb? Is there another way of doing such things by vectorization?
Thanks in advance,
Nachi