News for hackers. Stuff that matters.

Ask HN: 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.

( 2 comments | 3 points | on HN )
Re:Ask HN: Where can I find examples and resources on how to... by oliverx0 on Sunday February 02, 2020 @12:16PM (#22217975)
Re:Ask HN: Where can I find examples and resources on how to... by adamnemecek on Friday January 31, 2020 @01:45PM (#22204282)
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.