gpt4 book ai didi

c++ - Eigen3 replicate() 用于矩阵 vector cwiseProduct 操作

转载 作者:太空狗 更新时间:2023-10-29 20:24:59 24 4
gpt4 key购买 nike

我有以下代码:

Eigen::MatrixXf aMatrix( 3, 5 );
aMatrix <<
1, 0, 1, 0, 1,
0, 1, 0, 1, 0,
1, 1, 1, 1, 1;

Eigen::VectorXf aVector( 5 );
aVector << 3, 4, 5, 6, 7;

cout << aMatrix.cwiseProduct( aVector.replicate( 1, aMatrix.rows() ).transpose() ) << endl;

哪些输出:

3 0 5 0 7
0 4 0 6 0
3 4 5 6 7

有没有比使用 replicate() 调用更有效的方法来实现这一点?

最佳答案

已解决(在以下帮助下:How can I apply bsxfun like functionality at Eigen?)

这些是等价的:

aMatrix.cwiseProduct( aVector.replicate( 1, aMatrix.rows() ).transpose() )
aMatrix.array().rowwise() * aVector.array().transpose()

关于c++ - Eigen3 replicate() 用于矩阵 vector cwiseProduct 操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25492785/

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