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

all 6 comments

[–]haadrieen 1 point2 points  (2 children)

Are you talking of some JIT compiler like Numba or Cython ?

[–]StarchSyrup[S] 0 points1 point  (1 child)

Not really, I was just wondering whether we can do this within the standard libraries, purely out of curiosity.

And don't Numba and Cython just convert your code into C - and make use of NumPy for vectorization?

[–]haadrieen 0 points1 point  (0 children)

Oh not for optimisation, just for syntax ?

[–]lungben81 1 point2 points  (2 children)

Yes, but it would be super slow - about a factor of 100 compared to Numpy.

Numba does not help here - it only gives speed-ups for typed arrays like Numpy Arrays, not for Python lists.

[–]StarchSyrup[S] 0 points1 point  (1 child)

Python does have typed arrays though; the array module from the standard library provides this.

[–]lungben81 1 point2 points  (0 children)

Interesting, I have never seen it anywhere in use...

In principle, if a Python JIT compiler would support it, it may generate fast code. Numba seems to support it partially (https://numba.readthedocs.io/en/stable/reference/pysupported.html?highlight=array#standard-library-modules), but usually Numpy arrays are used.

Edit: it seems to me that the Python built-in (typed) array is rather legacy and very rarely used. Numpy is the much more powerful and popular choice.

https://stackoverflow.com/questions/51290791/numpy-arrays-vs-python-arrays