Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何使用 Eigen3 执行元素乘法?
做
a = a.cwiseProduct(b);
原地跑?或者是
a.array() *= b.array();
在风格和性能方面更好的解决方案?
两个表达式都应该生成相同的代码(使用合理优化的编译器),所以这更像是一个品味问题。
如果您主要使用元素进行操作,a您b应该将它们声明为Eigen::Array(而不是Eigen::Matrix),然后只写a*=b;. 如果您以后需要访问a或b以矩阵方式访问,您仍然可以使用a.matrix().
a
b
Eigen::Array
Eigen::Matrix
a*=b;
a.matrix()