[PYTHON MATRIX-SIG] Numeric.clip oddity

Roger Burnham rburnham@cri-inc.com
Wed, 7 May 1997 14:02:36 -5000


Hi,

I'm working with 2D arrays and found this:

# mag.typecode() =='b'
# delta.typecode() == 'd'

   ret = mag - delta

   minV = Numeric.minimum.reduce(Numeric.minimum.reduce(ret))
   maxV = Numeric.maximum.reduce(Numeric.maximum.reduce(ret))
   print 'before min/max', minV, maxV

   ret = Numeric.clip(ret+0.5, 0.0, 255.0)

   minV = Numeric.minimum.reduce(Numeric.minimum.reduce(ret))
   maxV = Numeric.maximum.reduce(Numeric.maximum.reduce(ret))
   print 'after min/max', minV, maxV

outputs:
   before min/max -7.1836 234.0
   after min/max 0.0 255.0


while clipping with

   ret = Numeric.clip((ret+0.5).astype(Numeric.Int), 0, 255)

outputs what you would expect:
   before min/max -7.1836 234.0
   after min/max 0 234

As this is part of a computation that produces an image, I'm able to 
see that in fact some of the pixels that should have came out near 0, 
are coming out of the 'clip' at 255.

Is this a bug, or more probably, a flaw in my understanding?

Thanks,



Roger Burnham
Cambridge Research & Instrumentation
21 Erie Street
Cambridge, MA 02139
rburnham@cri-inc.com

_______________
MATRIX-SIG  - SIG on Matrix Math for Python

send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
_______________