Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要使用 Eigen 库在 C++ 中创建一个对角线 MatrixXd,其中对角线上的元素是较短 VectorXd 的 N 次复制。
矢量Xd R; // 大小为 n 的向量
矢量Xd V; // 一个大小为 n*N 的向量,对应于 R 的 N 个连接副本,我不知道如何创建
MatrixXd D=MatrixXd(V.asDiagonal()); //我的对角矩阵大小为 n N xn N
谢谢。
类似的东西
VectorXd V(N * R.innerSize()); // construct vector of size N * n for(size_t i = 0; i < n; ++i) for(size_t j = 0; j < R.innerSize(); ++j) V[i * R.innerSize() + j] = R[j];