Re:Python for Data Analysis (new O'Reilly book from creator ...
by ballooney on Friday May 25, 2012 @01:56AM
(#4022133)
I would add that an advantage of Matlab for number bashing is a much more native handling of linear algebra. Let's say you have two matrices A and B, in matlab I could write:
Whereas in python it would be (approximately):
so matlab can evaluate everything in the right order (right to left) whereas for numpy I end up writing a little recursive function to dot a list of arguments together from right to left, which feels a bit cludgey and more of an impediment to getting your ideas down in code. Especially when your equations get very big as they often do with stats!
[ Parent
| on HN ]
Re:Python for Data Analysis (new O'Reilly book from creator ...
by lbolla on Friday May 25, 2012 @08:24AM
(#4023165)
If you intend "matrix multiplication", there is no "right order": "matrix multiplication" is associative (http://en.wikipedia.org/wiki/Matrix_multiplication).
Numpy has a "matrix" type, so you can write:
In [7]: A = numpy.matrix('1 2; 3 4; 5 6')
In [8]: B = numpy.matrix('1 2 3; 4 5 6')
In [9]: C = numpy.matrix('1; 2; 3')
In [10]: A * B * C
Out[10]:
matrix([[ 78],
[170],
[262]])
In [11]: (A * B) * C
Out[11]:
matrix([[ 78],
[170],
[262]])
In [12]: A * (B * C)
Out[12]:
matrix([[ 78],
[170],
[262]])
Re:Python for Data Analysis (new O'Reilly book from creator ...
by maxerickson on Friday May 25, 2012 @08:52AM
(#4023234)
It isn't native, but numexpr is a nice in between: