HACKER Q&A
📣 neomatrix369

Where can I find examples and resources on how to vectorize in Python?


Mainly the lambda like or .apply() like code styles? Where can I find examples and resources on how to vectorize code in Python (for fast Pandas and Numpy execution), for e.g. vectorize code like this: def some_function(): return group_series.apply(lambda x: x.astype(some_type).rolling(some_number).sum().shift(some_number))

or even something like this: def some_function(): return some_grouped_data_series.apply( lambda x: x.some_function(param1=value1, param2=value2).mean().shift(some_number) )

Mainly the lambda like or .apply() like code styles

Any suggestions I should try to vectorize the above, I tried a few things but it complains or I get undesired results. My python performance shares can be found here: https://github.com/neomatrix369/awesome-ai-ml-dl/blob/master/Programming-in-Python.md#performance, please feel free to share yours via a PR.


  👤 oliverx0 Accepted Answer ✓

👤 adamnemecek
I know this is a terrible answer but consider checking out Julia. In Julia, vectorization is a macro, you literally do this

@simd for x in 1:9 factorial *= x end

and the @simd macro handles conversion from loop to simd.