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

Discussion in 'Python' started by suzaku, Dec 15, 2012.

  1. suzaku

    suzaku Guest

    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.
    suzaku, Dec 15, 2012
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. donbro
    Replies:
    2
    Views:
    525
    donbro
    Nov 1, 2005
  2. Ulrich Dorda

    float64 print digits

    Ulrich Dorda, Mar 2, 2007, in forum: Python
    Replies:
    2
    Views:
    1,308
    Grant Edwards
    Mar 2, 2007
  3. Replies:
    5
    Views:
    483
    Victor Bazarov
    Jan 23, 2007
  4. Explore_Imagination

    How to Convert uint64 to uint32

    Explore_Imagination, Dec 10, 2008, in forum: C++
    Replies:
    21
    Views:
    7,753
    Triple-DES
    Dec 15, 2008
  5. Explore_Imagination
    Replies:
    3
    Views:
    1,948
    Saju Pillai
    Dec 11, 2008
Loading...

Share This Page