我有一个矩阵大小的NxM,并希望创建一个大小为N / 2×M的复数矩阵,其中实数是矩阵的左侧,复杂的部分是右侧。
我想出了这个:
auto complexmatrix= Shapes.block(0,0,Shapes.rows(),data.cols()) * std::complex<float>(1,0) + Shapes.block(0,data.cols(),Shapes.rows(),data.cols())*std::complex<float>(0,1); std::cout << complexmatrix<< std::endl;这可以优化,还是有更好的方法来创建复杂的矩阵。
总而言之,代码就像这样结束了。 感觉就像我错过了Eigen的东西。 目标是转换为复合符号并从每行中减去行方式。
//Complex notation and Substracting Mean. Eigen::MatrixXcf X = Shapes.block(0,0,Shapes.rows(),data.cols()) * std::complex<float>(0,1) + Shapes.block(0,data.cols(),Shapes.rows(),data.cols())*std::complex<float>(1,0); Eigen::VectorXcf Mean = X.rowwise().mean(); std::complex<float> *m_ptr = Mean.data(); for(n=0;n<Mean.rows();++n) X.row(n) = X.row(n).array() - *m_ptr++;I have a matrix sized NxM and would like to create a matrix of complex numbers of size N/2 x M where the real numbers are the left side of the matrix and the complex part is the right side.
I came up with this:
auto complexmatrix= Shapes.block(0,0,Shapes.rows(),data.cols()) * std::complex<float>(1,0) + Shapes.block(0,data.cols(),Shapes.rows(),data.cols())*std::complex<float>(0,1); std::cout << complexmatrix<< std::endl;Can this be optimized or are there a better way to create the complex matrix.
All in all, the code ended up like this. Feels like i am missing something from Eigen. The goal was to convert to Complex notation and subtract the row-wise mean from each row.
//Complex notation and Substracting Mean. Eigen::MatrixXcf X = Shapes.block(0,0,Shapes.rows(),data.cols()) * std::complex<float>(0,1) + Shapes.block(0,data.cols(),Shapes.rows(),data.cols())*std::complex<float>(1,0); Eigen::VectorXcf Mean = X.rowwise().mean(); std::complex<float> *m_ptr = Mean.data(); for(n=0;n<Mean.rows();++n) X.row(n) = X.row(n).array() - *m_ptr++;最满意答案
这是一个更简单的代码版本,可以更好地使用Eigen:
int cols = 100; int rows = 100; MatrixXf Shapes(rows, 2*cols); MatrixXcf X(rows, cols); X.real() = Shapes.leftCols(cols); X.imag() = Shapes.rightCols(cols); X.array().colwise() -= X.rowwise().mean().array();Here is a simpler version of your code making a better usage of Eigen:
int cols = 100; int rows = 100; MatrixXf Shapes(rows, 2*cols); MatrixXcf X(rows, cols); X.real() = Shapes.leftCols(cols); X.imag() = Shapes.rightCols(cols); X.array().colwise() -= X.rowwise().mean().array();更多推荐
发布评论