[Numpy-discussion] Output dtype
Keith Goodman
kwgoodman at gmail.com
Mon Dec 13 15:32:25 EST 2010
On Mon, Dec 13, 2010 at 12:20 PM, Bruce Southey <bsouthey at gmail.com> wrote:
> On 12/13/2010 11:59 AM, Keith Goodman wrote:
>> > 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.
>> _______________________________________________
>> NumPy-Discussion mailing list
>> NumPy-Discussion at scipy.org
>> http://mail.scipy.org/mailman/listinfo/numpy-discussion
> Unless something has changed since the docstring was written, this is
> probably an inherited 'bug' from np.mean() as the author expected that
> the docstring of mean was correct. For my 'old' 2.0 dev version:
>
> >>> np.mean( np.array([[0,1,2,3,4,5]], dtype='float32'), axis=1).dtype
> dtype('float32')
> >>> np.mean( np.array([[0,1,2,3,4,5]], dtype='float32')).dtype
> dtype('float64')
Same issue with np.std and np.var.
More information about the NumPy-Discussion
mailing list