[Numpy-discussion] Clipping, casting, and maximum values

Edward C. Jones edcjones at comcast.net
Mon Jan 2 09:54:11 CST 2006

#! /usr/bin/env python

import numarray
from numarray.numerictypes import *

# Is this program too complicated?
# On my machine (AMD64 chip, Debian unstable i386, numarray 1.5.0):
#    float(2**63-1) == float(2**63)
def clipcast(farr):
    if farr.type() != Float64:
        raise TypeError('input must be a Float64 array')
    farr = numarray.clip(farr, 0.0, float(2**63))
    print 'L13 %30.4f' % farr[0]
    top = (farr == float(2**63))
    arr = farr.astype(Int64)
    return numarray.where(top, 2**63-1, arr)

farr = numarray.array([1.0e300], Float64)
print farr.type(), farr[0]
arr = clipcast(farr)
print arr.type(), arr[0]

More information about the Numpy-discussion mailing list