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

Matthew Brett matthew.brett at gmail.com
Mon Jan 7 16:31:43 EST 2013


Hi,

On Mon, Jan 7, 2013 at 9:18 PM, Andrew Collette
<andrew.collette at gmail.com> wrote:
> Hi Matthew,
>
>> In this case I think you'd probably agree it would be reasonable to
>> raise an error - all other things being equal?
>
> No, I don't agree.  I want there to be some default semantics I can
> rely on.  Preferably, I want it to do the same thing it would do if
> some_offset were an array with element-by-element offsets, which is
> the current behavior of numpy 1.6 if you assume a reasonable dtype for
> some_offset.

Ah - well - I only meant that raising an error in the example would be
no more surprising than raising an error at the python prompt.  Do you
agree with that?  I mean, if the user knew that:

>>> np.array([1], dtype=np.int8) + 128

would raise an error, they'd probably expect your offset routine to do the same.

>> Can you think of another practical case where it would be reasonably
>> clear that it was the wrong thing to do?
>
> I consider "myarray + constant -> Error" clearly wrong no matter what
> the context.  I've never seen it in any other analysis language I've
> used.  But it's also possible that I'm alone in this... I haven't seen
> many other people here arguing against the change.

I agree it kind of feels funny, but that's why I wanted to ask you for
some silly but specific example where the funniness would be more
apparent.

Cheers,

Matthew



More information about the NumPy-Discussion mailing list