How can I apply bsxfun like functionality at Eigen?

匿名 (未验证) 提交于 2019-12-03 01:20:02

问题:

Suppose I have a matrix A which is n x n matrix and I have a vector b which is n x 1 vector and I want to calculate the following implementation in Eigen library.

bsxfun(@rdivide, A, b) 

How can I apply it Eigen ?

回答1:

How about this one:

Eigen::MatrixXf A(n,n); Eigen::VectorXf b(n);  A.cwiseQuotient( b.replicate(1,A.cols()) ) 

Here is one without replication, equivalent to bsxfun in MATLAB:

A.array().colwise() / b.array() 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!