[Numpy-discussion] clip() with None as argument

Friedrich Romstedt friedrichromstedt@gmail....
Tue Sep 7 15:08:31 CDT 2010

I just came across a problem with the intention to specify unset
boundaries given to numpy.clip() or array.clip():

a.clip(1e-10, None)
a.clip(None, -1e-10)

When doing this, the returned array is dtype=numpy.object, seemingly
None gets converted to a numpy.asarray(None, dtype=numpy.object), and
this is then used for the comparison.  Since (*any number* > None) is
true, and (*any number* < None) is false, it works or not, depending
on the usecase, despite one is still left with a dtype=numpy.object
array.  Precisely, using None as the lower boundary semi-works, while
using None as the upper boundary doesn't match expectations at all.

One can work around this, sure, but in my opinion it would be handy
anyway to have clip() interpret None as argument as \pm \infty.  Maybe
I'm just missing the appropriate function, though.


More information about the NumPy-Discussion mailing list