[Numpy-discussion] Inconsistent output dtype in mixed scalar-array operations

Charles R Harris charlesr.harris at gmail.com
Tue May 10 13:27:19 EDT 2011


On Tue, May 10, 2011 at 11:16 AM, Olivier Delalleau <shish at keba.be> wrote:

> Hi,
>
> I opened a ticket about this (http://projects.scipy.org/numpy/ticket/1827
> ),
> but thought I'd also ask on the mailing list whether this is working as
> intended.
>
> It looks like the resulting dtype of a "+" operation between a scalar and
> an
> array can depend on the order of the arguments. This seems wrong.
>
> Tested with numpy 1.5.1 under Ubuntu 11.04 (64-bit).
>
> In [4]: (numpy.array(0, dtype='uint16') + numpy.array([1],
> dtype='int8')).dtype
> Out[4]: dtype('int16')
>
> In [6]: (numpy.array([1], dtype='int8') + numpy.array(0,
> dtype='uint16')).dtype
> Out[6]: dtype('int8')
>
> Thanks for any feedback,
>
>
This has been fixed in the coming 1.6.0 release.

In [2]: (numpy.array(0, dtype='uint16') +
numpy.array([1],dtype='int8')).dtype
Out[2]: dtype('int8')

In [3]: (numpy.array([1], dtype='int8') +
numpy.array(0,dtype='uint16')).dtype
Out[3]: dtype('int8')

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20110510/12490e18/attachment.html>


More information about the NumPy-Discussion mailing list