制作矩阵的更好方法-Eigen中的对数运算? [英] A better way to make matrix - log operations in Eigen?

查看:256
本文介绍了制作矩阵的更好方法-Eigen中的对数运算?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在和Eigen一起使用矩阵和log/exp进行一些计算,但是我发现表达式有点笨拙(可能还会更慢?).有没有更好的方法来编写这样的计算?

I am playing around with Eigen doing some calculations with matrices and logs/exp, but I found the expressions I got a bit clumsy (and also possibly slower?). Is there a better way to write calculations like this ?

MatrixXd m = MatrixXd::Random(3,3);
m = m * (m.array().log()).matrix();

也就是说,不必转换为数组,然后返回矩阵?

That is, not having to convert to arrays, then back to a matrix ?

推荐答案

如果您要混合使用数组和矩阵运算,就不能真正避免使用它们,除非某些函数具有 cwise 函数,直接在矩阵上工作(例如, cwiseSqrt() cwiseAbs()).

If you are mixing array and matrix operations you can't really avoid them, except for some functions which have a cwise function which works directly on matrices (e.g., cwiseSqrt(), cwiseAbs()).

但是,当使用优化(在任何合理的编译器上)编译时, .array() .matrix()都不会对运行时产生影响.如果您认为这样更具可读性,则可以使用 unaryExpr() .

However, neither .array() nor .matrix() will have an impact on runtime when compiled with optimization (on any reasonable compiler). If you consider that more readable, you can work with unaryExpr().

这篇关于制作矩阵的更好方法-Eigen中的对数运算?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆