numpy vs python

przeciez każdy wie ze numpy jest szybszy niz modul math pythona, o ** juz nie wspominając że co? :exploding_head: :laughing: Mr DS on X: "@karpathy Never thought of about it before. Tested vanilla sqrt too and appears to be a tiny bit faster." / X

Reactions: :exploding_head: ×1 (billy pompom)

https://stackoverflow.com/questions/52603487/speed-comparison-numpy-vs-python-standard

dobrze wiedziec ze Tesla tez nie wiedziala :slightly_smiling_face:

To nie jest jakiś myk z narzutem związanym z wołaniem zewnętrznego interfejsu?

Tzn. numpy jest szybsze o ile wszystkie typy i obliczenia robisz w Numpy a nie przerzucasz z Pythona do numpy i spowrotem?

tak pisza w so:

numpy is only really a performance improvement for large blocks of data. The overhead of making sure the memory blocks line up correctly before pouring an ndarray into a c-compiled numpy function will generally overwhelm any time benefit if the array isn’t relatively large. This is why so many numpy questions are basically “How do I take this loopy code and make it fast,” and why it is considered a valid question in this tag where nearly any other tag will toss you to Code review before they get past the title.

So, yes, your observation is generalizable. Vectorizing is the whole point of numpy. numpy code that isn’t vectorized is always slower than bare python code, and is arguably just as “wrong” as cracking a single walnut with a jackhammer. Either find the right tool or get more nuts.

no to poklepię się po plecach, że dobrze zgadłem

Reactions: :+1: ×1 (miwojc)