r/Python • • Aug 05 '19

Python's response to MATLAB

Post image
4.3k Upvotes

372 comments sorted by

View all comments

Show parent comments

0

u/I_Feel_It_Too Aug 08 '19

Actually, the equivalent is

auto m = Vector3d(1,2,4).sqrt().asDiagonal();

This code has the major advantage of being strongly typed and giving a sparse matrix. It's arguably much more readable than the Matlab equivalent, but some people prefer fewer keystrokes, so which is better is more a matter of taste. If you'd rather just print it to the screen, do this:

cout << Matrix3d(Vector3d(1,2,3).asDiagonal()).sqrt();

Now, how to you make a list in Matlab? You literally can't.

1

u/mexiKobe Aug 09 '19 edited Aug 09 '19

https://eigen.tuxfamily.org/dox/TopicPitfalls.html

"In short: do not use the auto keywords with Eigen's expressions, unless you are 100% sure about what you are doing. In particular, do not use the auto keyword as a replacement for a Matrix<> type."

(not that either of those expressions would be equivalent to the MATLAB one anyways)

as for lists, you would use cells in MATLAB: https://www.mathworks.com/help/matlab/ref/cell.html

Again, you do not know what you're talking about despite being a bloviating asshole.