[Python-ideas] Fast sum() for non-numbers

Oscar Benjamin oscar.j.benjamin at gmail.com
Thu Jul 11 19:21:43 CEST 2013


On 11 July 2013 18:12, Ron Adam <ron3200 at gmail.com> wrote:
> I think this is what it should do.
>
> I tried overiding lists __add__, but that didn't work as nice.  It needs to
> have a starting list with all zeros in it.  How does numpy get around that?

Like so:

>>> import numpy
>>> a = numpy.array([1, 2, 3])
>>> a
array([1, 2, 3])
>>> a + 0
array([1, 2, 3])
>>> a + 1
array([2, 3, 4])


Oscar


More information about the Python-ideas mailing list