【发布时间】:2016-01-30 20:10:24
【问题描述】:
我有两个相同维度的巨大矩阵。我想计算它们之间的欧几里得距离。我知道这是功能:
euclidean_distance <- function(p,q){
sqrt(sum((p - q)^2))
}
and if these are two matrices:
set.seed(123)
mat1 <- data.frame(x=sample(1:10000,3),
y=sample(1:10000,3),
z=sample(1:10000,3))
mat2 <- data.frame(x=sample(1:100,3),
y=sample(1:100,3),
z=sample(1:1000,3))
那么我需要一个新的 3*3 矩阵来显示 mat1 和 mat2 的每对值之间的欧几里得距离。
有什么建议吗?
【问题讨论】:
-
@AndresT 我希望输出也是一个矩阵
标签: r