Hi All,

I am trying to convert the following piece of matlab code to R:

XX1 = sum(w(:,ones(1,N1)).*X1.*X1,1);          #square the elements of X1,
weight it and repeat this vector N1 times
XX2 = sum(w(:,ones(1,N2)).*X2.*X2,1);          #square the elements of X2,
weigh and repeat this vector N2 times
X1X2 = (w(:,ones(1,N1)).*X1)'*X2;                 #get the weighted
'covariance' term
XX1T = XX1';                                              #transpose
z = XX1T(:,ones(1,N2)) + XX2(ones(1,N1),:) - 2*X1X2;            #get the
squared weighted distance

which is basically doing: z=(X1-X2)' W (X1-X2)

What would the best way (for SPEED) to do this? or is vectorizing as above
the best? Any hints, suggestions?

Thanks,
Sachin

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to