[Numpy-discussion] Do we want scalar casting to behave as it does at the moment?

Olivier Delalleau shish@keba...
Tue Jan 8 16:41:34 CST 2013

Le mardi 8 janvier 2013, Andrew Collette a écrit :

> Hi Dag,
> > So you are saying that, for an array x, you want
> >
> > x + random.randint(100000)
> >
> > to produce an array with a random dtype?
> Under the proposed behavior, depending on the dtype of x and the value
> from random, this would sometimes add-with-rollover and sometimes
> raise ValueError.
> Under the 1.5 behavior, it would always add-with-rollover and preserve
> the type of x.
> Under the 1.6 behavior, it produces a range of dtypes, each of which
> is at least large enough to hold the random int.
> Personally, I prefer the third option, but I strongly prefer either
> the second or the third to the first.
> Andrew

Keep in mind that in the third option (current 1.6 behavior) the dtype is
large enough to hold the random number, but not necessarily to hold the
result. So for instance if x is an int16 array with only positive values,
the result of this addition may contain negative values (or not, depending
on the number being drawn). That's the part I feel is flawed with this
behavior, it is quite unpredictable.

-=- Olivier
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20130108/eb1eb192/attachment.html 

More information about the NumPy-Discussion mailing list