[Numpy-discussion] ndarray.clip only with lower or upper values?

Hans Meine meine at informatik.uni-hamburg.de
Tue Dec 11 04:32:05 EST 2007


Am Montag, 10. Dezember 2007 23:46:17 schrieb Timothy Hochberg:
> > TypeError: function takes at least 2 arguments (1 given)
> >
> > (I could simulate that by passing max = maximum_value_of(a.dtype), if
> > that existed, see my other mail.)
>
> Why not just use minimum or maximum as needed instead of overloading clip?

You mean one of the following?
  a.clip(min = 10, max = numpy.finfo(a.dtype).max)
  a.clip(min = 10, max = numpy.iinfo(a.dtype).max)

Three reasons:
- this is not very concise
- it is less efficient than specialized clip variants
  (not much / too important though)
- I would have to discriminate integral and floating point types

How is the latter done in numpy?  Is there a good reason not to have 
numpy.rangetraits(sometype) with min/max as in iinfo/finfo?
Should I use isinstance(mytype, int)?

-- 
Ciao, /  /
     /--/
    /  / ANS



More information about the NumPy-Discussion mailing list