This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author rhettinger
Recipients rhettinger, urielias
Date 2018-02-21.17:54:40
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1519235680.36.0.467229070634.issue32895@psf.upfronthosting.co.za>
In-reply-to
Content
> 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.
History
Date User Action Args
2018-02-21 17:54:40rhettingersetrecipients: + rhettinger, urielias
2018-02-21 17:54:40rhettingersetmessageid: <1519235680.36.0.467229070634.issue32895@psf.upfronthosting.co.za>
2018-02-21 17:54:40rhettingerlinkissue32895 messages
2018-02-21 17:54:40rhettingercreate