by rrrrtttt · 13y ago · 0 comments
For example, let's say I want to apply DCT to a matrix. In Matlab it's simply dct(A). How do you do that in Python? Well, there's scipy.fftpack.dct, but when I try it, it turns out it operates on the rows of A, instead of the columns. So I start searching the help, and find there's a parameter called "axis", with the useless description "Axis over which to compute the transform." So I try axis=1, axis=2, then finally axis=0, and presto, it works. So sure, it's functionally equivalent to Matlab, but do I really want to go through all this every time I want to accomplish a simple task?
Where they really shine though, is scientific code that needs to do a bit more than numerical computation. I've tried Matlab briefly, and it was hell. Things like parsing strange text files for the source data, scraping data from websites, pulling data in from a SQL database, or publishing the computation as a web service are all easy with Python.
Spending a small bit of extra time on the core matrix code is okay to get the rest of the Python ecosystem and libraries (and even for loops that make sense).
SciPy's DCT is meant for multidimensional arrays. Array indexing begins at 0 in Python, just like it does in many other languages. So, it's only natural that they'd count axis numbers that way too.
> do I really want to go through all this every time I want to accomplish a simple task?
Entirely your choice. Your choice is not a reflection on the quality of the product.
Scipy/Numpy/Pandas are, at the moment, not the comprehensive, well documented and consistent platform that Matlab is. Simple things like a less than painless install process and numpy examples like "a*b" can be element wise multiplication or matrix multiplication pending if "a" is array or matrix are enough to put of my coworkers off for at least a year or two before contemplating a switch again.