FW: [Numpy-discussion] Bug: extremely misleading array behavior
perry at stsci.edu
Fri Jun 7 09:43:02 CDT 2002
> > For binary operations between a Python scalar and array, there is
> > no coercion performed on the array type if the scalar is of the
> > same kind as the array (but not same size or precision). For example
> > (assuming ints happen to be 32 bit in this case)
> That solves one problem and creates another... Two, in fact. One is
> the inconsistency problem: Python type coercion always promotes
> "smaller" to "bigger" types, it would be good to make no exceptions
> from this rule.
> Besides, there are still situations in which types, ranks, and
> indexing operations depend on each other in a strange way. With
> a = array([1., 2.], Float)
> b = array([3., 4.], Float32)
> the result of
> is of type Float, whereas
> is of type Float32 - if and only if a has rank 1.
All this is true. It really comes down to which poison you
prefer. Neither choice is perfect. Changing the coercion rules
results in the inconsistencies you mention. Not changing them
results in the existing inconsistencies recently discussed
(and still doesn't remove the difficulties of dealing with
scalars in expressions without awkward constructs). We think
the inconsistencies you point out are easier to live with than
the existing behavior.
It would be nice to have a solution that had none of these
problems, but that doesn't appear to be possible.
More information about the Numpy-discussion