gpt4 book ai didi

c++ - 特征值:从 vector 中减去标量

转载 作者:可可西里 更新时间:2023-11-01 18:42:35 26 4
gpt4 key购买 nike

我在使用 Eigen 库时遇到错误,我想做的就是从 Eigen::VectorXf 中减去一个标量。所以,我的代码如下:

#define VECTOR_TYPE Eigen::VectorXf
#define MATRIX_TYPE Eigen::MatrixXf

// myMat is of MATRIX_TYPE
JacobiSVD<MATRIX_TYPE> jacobi_svd(myMat,ComputeThinU | ComputeThinV);

const float offset = 3.0f;
VECTOR_TYPE singular_values = jacobi_svd.singularValues();

VECTOR_TYPE test = singular_values - offset;

最后一行导致编译错误:

error: invalid operands to binary expression ('Eigen::VectorXf' (aka 'Matrix') and 'float') VECTOR_TYPE test = singular_values - scale;

Eigen/src/Core/../plugins/CommonCwiseBinaryOps.h:19:28: note: candidate template ignored: could not match 'MatrixBase' against 'float' EIGEN_MAKE_CWISE_BINARY_OP(operator-,internal::scalar_difference_op)

最佳答案

最简单的是移动到所谓的"array"。世界:

VECTOR_TYPE test = singular_values.array() - offset;

关于c++ - 特征值:从 vector 中减去标量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35688805/

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