Raymond Hettinger <raymond.hettin...@gmail.com> added the comment:

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

----------
nosy: +rhettinger

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue32895>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to