1
votes

I have a matrix that represents a group of column vectors in DolphinDB. Each row is regarded as a component of the vector and each column is regarded as a column vector.

For example, the following 3*4 matrix A represents 4 column vectors with 3 components.

A = (1 4 5 -2 -3 6 9 4 3 1 0 3)$3:4

I would like to compute the pairwise Euclidean distance of those vectors. Is there any way to avoid using a FOR loop?

1

1 Answers

1
votes
A = (1 4 5 -2 -3 6 9 4 3 1 0 3)$3:4
cross(def(x,y): sum2(x -y).sqrt(), A)

DolphinDB has a higher order function cross to solve pairwise problems. Here we define a lambda function to calculate Euclidean distance