[Numpy-discussion] Output dtype
Keith Goodman
kwgoodman@gmail....
Mon Dec 13 11:59:48 CST 2010
>From the np.median doc string: "If the input contains integers, or
floats of smaller precision than 64, then the output data-type is
float64."
>> arr = np.array([[0,1,2,3,4,5]], dtype='float32')
>> np.median(arr, axis=0).dtype
dtype('float32')
>> np.median(arr, axis=1).dtype
dtype('float32')
>> np.median(arr, axis=None).dtype
dtype('float64')
So the output doesn't agree with the doc string.
What is the desired dtype of the accumulator and the output for when
the input dtype is less than float64? Should it depend on axis?
I'm trying to duplicate the behavior of np.median (and other
numpy/scipy functions) in the Bottleneck package and am running into a
few corner cases while unit testing.
Here's another one:
>> np.sum([np.nan]).dtype
dtype('float64')
>> np.nansum([1,np.nan]).dtype
dtype('float64')
>> np.nansum([np.nan]).dtype
<snip>
AttributeError: 'float' object has no attribute 'dtype'
I just duplicated the numpy behavior for that one since it was easy to do.
More information about the NumPy-Discussion
mailing list