【问题标题】:Eigen SVD Double Cast特征 SVD 双铸
【发布时间】:2026-02-20 16:50:01
【问题描述】:

我正在尝试使用 EIGEN 库。特别是我正在使用 SVD。

计算奇异值后我需要执行这个操作:

svd.singularValues()/svd.singularValues().row(1)

这是一个被标量潜水的向量。

我的问题是:

1) 为什么这个操作给了我:

main.cpp:149:56: error: no match for ‘operator/’(操作数类型是 'const SingularValuesType {aka const Eigen::Matrix}' 和 'Eigen::DenseBase >::ConstRowXpr {aka const Eigen::Block, 1, 1, false>}')

2) 如何将包含在标准“double”变量中的 svd.singularValues().row(1) 中的值复制到?

【问题讨论】:

    标签: eigen


    【解决方案1】:

    请注意,svd.singularValues().row(1) 不是标量,而是1x1 矩阵,这就是您的代码无法编译的原因。解决方案:

    svd.singularValues()/svd.singularValues()(1)
    

    还要注意,像往常一样在 C/C++ 中,特征矩阵和向量是从 0 开始索引的,所以如果你想通过最大奇异值进行归一化,你应该这样做:

    svd.singularValues()/svd.singularValues()(0)
    

    【讨论】: