How can I apply bsxfun functionality on Eigen?

Suppose I have a matrix A, which is an nxn matrix, and I have a vector b, which is a vector nx 1, and I want to calculate the next implementation in the Eigen library.

bsxfun(@rdivide, A, b) 

How can I apply it eigen?

+4
source share
1 answer

How about this:

 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() 
+2
source

Source: https://habr.com/ru/post/1498601/


All Articles