gpt4 book ai didi

r - R 中的 L1 和 L2 范数

转载 作者:行者123 更新时间:2023-12-04 10:42:43 27 4
gpt4 key购买 nike

我有一个矢量 e <- c(0.1, -0.1, 0.1)我想计算 L1 和 L2 范数。我正在使用 norm(e, type="2")这适用于 L2 规范,但当我将其更改为 norm(e, type="1") 时或 norm(e, type="I") , R-Studio 返回以下错误:

Error in norm(e, type = "1") : 'A' must be a numeric matrix

如何解决这个问题?

最佳答案

要解决此问题,请使用 e <- as.matrix(c(0.1, -0.1, 0.1)) .

正下方是范数函数的主体,如果 type!="2" ,它会跳到 .Internal(La_dlange(x,type)) ,我想这会导致类型 2 特殊,但我无法进一步解释。

function (x, type = c("O", "I", "F", "M", "2")) 
{
if (identical("2", type)) {
svd(x, nu = 0L, nv = 0L)$d[1L]
}
else .Internal(La_dlange(x, type))
}

关于r - R 中的 L1 和 L2 范数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42049895/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com