[Numpy-discussion] clip with None argument changes dtype
Jonathan Slavin
jslavin at cfa.harvard.edu
Wed May 1 11:20:21 EDT 2013
Hi all,
I'm wondering if you think the following behavior in numpy.clip is a bug
(it certainly confused me for a while):
>>> x = np.arange(5.)
>>> xx = x.clip(None,3.)
>>> xx
array([0.0, 1.0, 2.0, 3.0, 3.0], dtype=object)
Since xx now has the dtype of object, doing things like
>>> np.exp(xx)
AttributeError Traceback (most recent call
last)
<ipython-input-6-30aa315cc2b1> in <module>()
----> 1 np.exp(xx)
Which, if you don't know about the change in the dtype is a very
confusing error message. It seems to me that either clip should give an
error message when None is given for the a_min argument or, better,
should not change the dtype of the input array as it does. This comes
up because I want to only clip the maximum. Of course you can clip the
minimum by simply omitting the second argument. The asymmetry of this
is not good, I think. I suppose that using the maximum function is
better in this situation (as I recently found out), though the docs make
it seem that one needs to supply two arrays -- even though you don't.
Jon
--
______________________________________________________________
Jonathan D. Slavin Harvard-Smithsonian CfA
jslavin at cfa.harvard.edu 60 Garden Street, MS 83
phone: (617) 496-7981 Cambridge, MA 02138-1516
cell: (781) 363-0035 USA
______________________________________________________________
More information about the NumPy-Discussion
mailing list