稀疏特征矩阵子集列 [英] Subset columns of sparse eigen matrix
本文介绍了稀疏特征矩阵子集列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Eigen::SparseMatrix<double> m;
std::vector<int> indices = {1, 5, 3, 6};
// error: type 'Eigen::SparseMatrix<double>' does not provide a call operator
m(Eigen::all, indices);
是否有解决办法?
更新1 已明确指定列可以按任意顺序排列。推荐答案
SparseMatrix实际上不提供任何operator()
,因此无法执行此操作。
编辑:以下内容针对的是旧版本的问题。
如果您的实际用例也具有要访问的列相邻的属性,则可以改用
SparseMatrix<double,ColMajor> m(5,5);
int j = 1;
int number_of_columns=2;
m.middleCols(j,number_of_columns) = ...;
还有m.leftCols(number_of_columns)
和m.rightCols(number_of_columns)
它们甚至是可写的,因为矩阵是以列为主的。
所有其他块表达式都已定义,但为只读,请参阅the corresponding Sparse Matrix documentation。
编辑:要回答更新的问题: 我猜你将无法避免抄袭。通过复制可以这样完成(未测试)
Eigen::SparseMatrix<double> m;
std::vector<int> indices = {1, 5, 3, 6};
Eigen::SparseMatrix<double> column_subset(m.rows(),indices.size());
for(int j =0;j!=column_subset.cols();++j){
column_subset.col(j)=m.col(indices[j]);
}
这篇关于稀疏特征矩阵子集列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文