Skip to content
Prev 269516 / 398502 Next

Efficient way to Calculate the squared distances for a set ofvectors to a fixed vector

Hi Wei Wu,

What about:

x <- matrix(rnorm(20000*5),ncol=5)
y <- rnorm(5)
distances <- rowSums((x-y)**2)

Cheers,

Tsjerk

On Wed, Aug 24, 2011 at 8:43 AM, Enrico Schumann
<enricoschumann at yahoo.de> wrote: