Reputation: 531
Python question:
print(sum(range(5),-1))
from numpy import *
print(sum(range(5),-1))
9
10
What is logical behind it? Thank you
Upvotes: 2
Views: 3103
Reputation: 4758
numpy.sum() signature is as follows (with some arguments omitted):
numpy.sum(a, axis=None, dtype=None, out=None, ...)
Python's sum
signature:
sum(iterable, start=0)
sum
iterates over supplied iterable, sums the values, and then adds -1 (i.e. substracts 1).
numpy.sum
just sums all the values from supplied iterable, and receives an axis
parameter as 1
, which in your case doesn't change the behaviour.
Upvotes: 4