sum returns numpy.float64 when applied to a sequence of numpy.uint64

S

suzaku

I came across this question on StackOverflow today: http://stackoverflow.com/questions/...tead-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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,999
Messages
2,570,243
Members
46,836
Latest member
login dogas

Latest Threads

Top