
Ask HN: Where can I find examples and resources on how to vectorize in Python? - neomatrix369
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))<p>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)
        )<p>Mainly the lambda like or .apply() like code styles<p>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:&#x2F;&#x2F;github.com&#x2F;neomatrix369&#x2F;awesome-ai-ml-dl&#x2F;blob&#x2F;master&#x2F;Programming-in-Python.md#performance, please feel free to share yours via a PR.
======
oliverx0
You are gonna love this: [https://www.labri.fr/perso/nrougier/from-python-to-
numpy/#co...](https://www.labri.fr/perso/nrougier/from-python-to-numpy/#code-
vectorization)

------
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.

