sum returns numpy.float64 when applied to a sequence of numpy.uint64
satorulogic at gmail.com
Sat Dec 15 10:40:13 CET 2012
I came across this question on StackOverflow today: http://stackoverflow.com/questions/13890451/why-numpy-sum-returns-a-float64-instead-of-an-uint64-when-adding-elements-of-a-g
I'm not familiar with `numpy` but I'm curious about this, so I started doing some experiments.
This is what I have discovered so far:
1. when a `generator ` is passed to `numpy.sum`, it fallback to use Python's built-in `sum`.
2. if elements of the sequence passed to `sum` is of type `numpy.uint64`, the result would be a number of type `numpy.float64`;
3. when I tried it with `numpy.int64`, the result is as expected: `numpy.int64`.
I guess the reason maybe that we don't really have `64 bits unsigned integer` in Python, so the numbers get converted to something different. And if so, I have no idea why it chose `float64` as the type.
More information about the Python-list