Message312497
> I think many programmers aren't aware of that, so all in all
> it can improve the performance of a lot of existing code.
We could create a __sum__ dunder method to allow classes to override the normal behavior of sum, but that isn't worth it because the speed issue has almost nothing to do with summation. For example, the timings would also be slow for min(a), max(a), list(a), set(a), etc where a=np.random.rand(int(1e6)).
In general, if anything outside of numpy loops over a numpy array, then every datum has to be converted to a typed, reference-counted python object before the function can begin to do its work. These are the facts-of-life when dealing with numpy. The usual advice is to manipulate numpy arrays only with numpy tools because they all know how to operate on the data natively without allocating Python objects for every datum. |
|
Date |
User |
Action |
Args |
2018-02-21 17:54:40 | rhettinger | set | recipients:
+ rhettinger, urielias |
2018-02-21 17:54:40 | rhettinger | set | messageid: <1519235680.36.0.467229070634.issue32895@psf.upfronthosting.co.za> |
2018-02-21 17:54:40 | rhettinger | link | issue32895 messages |
2018-02-21 17:54:40 | rhettinger | create | |
|