Reputation: 3733
This is a follow up to this question
I'm interested in understanding the speed implications of using a numpy array vs a list of lists when the array is of type object
.
If anyone is interested in the object I'm using:
import gmpy2 as gm
gm.mpfr('0') # <-- this is the object
Upvotes: 1
Views: 2219
Reputation: 365737
The biggest usual benefits of numpy, as far as speed goes, come from being able to vectorize operations, which means you replace a Python loop around a Python function call with a C loop around some inlined C (or even custom SIMD assembly) code. There are probably no built-in vectorized operations for arrays of mpfr
objects, so that main benefit vanishes.
However, there are some place you'll still benefit:
A.T
, yes, this is essentially free.np.vectorize
around a normal Python function, pretty much on the same order as the benefit you get from a list comprehension over a for statement.As for disadvantages… well, one obvious one is that using numpy restricts you to CPython or sometimes PyPy (hopefully in the future that "sometimes" will become "almost always", but it's not quite there as of 2014); if your code would run faster in Jython or IronPython or non-NumPyPy PyPy, that could be a good reason to stick with lists.
Upvotes: 2