[Numpy-discussion] max value of np scalars

Neal Becker ndbecker2 at gmail.com
Tue Sep 29 16:52:36 EDT 2009


I need the max value of an np scalar type.  I had used this code:

def get_max(is_signed, base_type, total_bits):
    print 'get_max:', is_signed, base_type, total_bits
    if is_signed:
        return (~(base_type(-1) << (total_bits-1)))
    else:
        print type(base_type (-1) << total_bits)
        return (~(base_type (-1) << total_bits))

This doesn't work for e.g., np.uint64.  As the 'print' shows,
 get_max: False <type 'numpy.uint64'> 10
<type 'long'>

The type of np.uint64 (-1) << 10 is not np.uint64, but long.  This seems 
very strange to me.

So, 2 questions.

1) Is this expected behavior?

2) How can I correctly implement get_max?




More information about the NumPy-Discussion mailing list