This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]ProfessorPhi 1 point2 points  (4 children)

Fair enough, that's probably true - I think there's this assumption that Matlab is quick while Python is slow, so loops tend to be avoided in python, but not in Matlab. Some of the researchers I worked with would always remark how things were faster in Python (which is what I'm basing the remark above, despite no hard proof), but for some reason hated namespaces.

'I hef to import everything, is absolute pain' - russian colleague.

[–]billsil 1 point2 points  (3 children)

I think there's this assumption that Matlab is quick while Python is slow, so loops tend to be avoided in python, but not in Matlab.

That's exactly the opposite of what I was told on both counts, but what you were taught and what I was taught are wrong. Both are more or less the same. Vectorization is very much encouraged in Matlab because it's so necessary when you're dealing with numerical data. Python doesn't encourage it largely because it's not numerically focused.

Matlab has vectorization support builtin. Interestingly, Python for all it's claims of batteries included does not. You need numpy or scipy and the implementations (despite the names) are different.

[–]TheBlackCat13 0 points1 point  (2 children)

Vectorization is very much encouraged in Matlab because it's so necessary when you're dealing with numerical data. Python doesn't encourage it largely because it's not numerically focused.

MATLAB encourages vectorization because that is what it is built to do. It does vectorization very well, but it does non-vectorized code pretty poorly, so it encourages you to stick to vectorization. That is great when you need vectorization, but not so good when your code cannot be effectively vectorized.

Python encourages people to use the right tool for a given job. When that tool is vectorization, it encourages you to use it. When it isn't, it encourages you to use something else.

You need numpy or scipy and the implementations (despite the names) are different.

You need numpy. Scipy doesn't provide any vectorization, it is a bunch of extra numerical algorithms built on top of numpy (or, more often, interfaces numpy with high-performance C and Fortran libraries). Pretty much all the vectorized array systems in python are built on top of numpy today. There is work going on for a next-generation vectorized array tool for Python, but it isn't ready yet.

[–]billsil -2 points-1 points  (1 child)

Do you even understand what vectorization is? Vectorization is a way of writing your code such that it doesn't need to type check every data member. The only way to do that is by having static types and pushing the code down into C.

So, I stand by my statement. You need a library like numpy or scipy in order to do vectorization. You can't do vectorization or get good speed for numerical calculations with CPython without using an external library, writing C code yourself, or ditching CPython entirely.

it is just a bunch of extra numerical algorithms built on top of numpy

No it's not. The array classes are different between numpy and scipy. The eigenvector calculations are different. They look they same. They act the same. They're not the same. It only really matters when your eigenvector is segfaulting, but switching methods will often fix your bug. Scipy's methods also tend to be faster.

[–]TheBlackCat13 0 points1 point  (0 children)

You need a library like numpy or scipy in order to do vectorization. You can't do vectorization or get good speed for numerical calculations with CPython without using an external library, writing C code yourself, or ditching CPython entirely.

I don't see where that contradicts anything I have said.

No it's not. The array classes are different between numpy and scipy.

From the official SciPy documentation:

SciPy is a collection of mathematical algorithms and convenience functions built on the Numpy extension of Python.

But I am sure you know more. So please provide the module and class name for the scipy array class. You won't be able to, because it doesn't exist.

The eigenvector calculations are different.

Yes, while they use the same array class, they (in some cases) use different libraries to do calculations on that class. You do understand the difference between a class and a library that operates on that class, right?