[Python-ideas] Fast sum() for non-numbers
Ron Adam
ron3200 at gmail.com
Thu Jul 11 20:29:08 CEST 2013
On 07/11/2013 12:21 PM, Oscar Benjamin wrote:
> 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
Right answer to the wrong question.
I was asking how numpy it gets around sum() needing a starting 'array'
argument? Not how numpy arrays work with '+'.
Cheers,
Ron
More information about the Python-ideas
mailing list