相关疑难解决方法(0)

(速度挑战)有没有更快的方法来计算两个矩阵行之间的距离矩阵(以欧几里德距离为单位)?

首先,这不是计算两个矩阵之间的欧几里德距离的问题。

假设我有两个矩阵xy,例如

set.seed(1)
x <- matrix(rnorm(15), ncol=5)
y <- matrix(rnorm(20), ncol=5)
Run Code Online (Sandbox Code Playgroud)

在哪里

> x
           [,1]       [,2]      [,3]       [,4]       [,5]
[1,] -0.6264538  1.5952808 0.4874291 -0.3053884 -0.6212406
[2,]  0.1836433  0.3295078 0.7383247  1.5117812 -2.2146999
[3,] -0.8356286 -0.8204684 0.5757814  0.3898432  1.1249309

> y
            [,1]       [,2]        [,3]       [,4]        [,5]
[1,] -0.04493361 0.59390132 -1.98935170 -1.4707524 -0.10278773
[2,] -0.01619026 0.91897737  0.61982575 -0.4781501  0.38767161
[3,]  0.94383621 0.78213630 -0.05612874  0.4179416 -0.05380504
[4,]  0.82122120 0.07456498 -0.15579551  1.3586796 -1.37705956
Run Code Online (Sandbox Code Playgroud)

然后我想获得distmat维度为 3×4 的距离矩阵,其中元素是来自or …

performance r matrix euclidean-distance

4
推荐指数
1
解决办法
1022
查看次数

标签 统计

euclidean-distance ×1

matrix ×1

performance ×1

r ×1