[Numpy-discussion] Output dtype

Keith Goodman kwgoodman at gmail.com
Mon Dec 13 12:59:48 EST 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

>> arr = np.array([[0,1,2,3,4,5]], dtype='float32')
>> np.median(arr, axis=0).dtype
>> np.median(arr, axis=1).dtype
>> np.median(arr, axis=None).dtype

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
>> np.nansum([1,np.nan]).dtype
>> np.nansum([np.nan]).dtype
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