how to calculate Euclidean distance between two matrices in R

后端 未结 2 1635
执念已碎
执念已碎 2021-01-05 13:10

I have two huge matrices with equal dimensions. I want to calculate Euclidean distance between them. I know this is the function:

euclidean_distance <- fu         


        
2条回答
  •  逝去的感伤
    2021-01-05 13:43

    This is a job for the base function outer:

    outer(mat1,mat2,Vectorize(euclidean_distance))
    
             x         y         z
    x  9220.40  9260.736  8866.034
    y 12806.35 12820.086 12121.927
    z 11630.86 11665.869 11155.823
    

提交回复
热议问题