如何在Eigen中创建复数矩阵(How do i create a matrix of complex numbers in Eigen)

编程入门 行业动态 更新时间:2024-10-19 21:32:49
如何在Eigen中创建复数矩阵(How do i create a matrix of complex numbers in Eigen)

我有一个矩阵大小的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();

更多推荐

本文发布于:2023-07-31 00:33:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1340512.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:复数   矩阵   如何在   Eigen   numbers

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!