Sum and product of an array: Difference between revisions
Content added Content deleted
Line 514: | Line 514: | ||
from functools import reduce |
from functools import reduce |
||
from operator import mul, add |
from operator import mul, add |
||
reduce(add, numbers) |
sum = reduce(add, numbers) # note: this version doesn't work with empty lists |
||
reduce( |
sum = reduce(add, numbers, 0) |
||
product = reduce(mul, numbers) # note: this version doesn't work with empty lists |
|||
product = reduce(mul, numbers, 1) |
|||
{{libheader|numpy}} |
{{libheader|numpy}} |