[Numpy-discussion] Matching 0-d arrays and NumPy scalars
Travis E. Oliphant
Thu Feb 21 09:03:16 CST 2008
Konrad Hinsen wrote:
> On 21.02.2008, at 08:41, Francesc Altet wrote:
>> Well, it seems like a non-intrusive modification, but I like the
>> to remain un-indexable, mainly because it would be useful to raise an
>> error when you are trying to index them. In fact, I thought that when
>> you want a kind of scalar but indexable, you should use a 0-d array.
> I agree. In fact, I'd rather see NumPy scalars move towards Python
> scalars rather than towards NumPy arrays in behaviour.
A good balance should be sought. I agree that improvements are needed,
especially because much behavior is still just a side-effect of how
things were implemented rather than specifically intentional.
> In particular,
> their nasty habit of coercing everything they are combined with into
> arrays is still my #1 source of compatibility problems with porting
> code from Numeric to NumPy. I end up converting NumPy scalars to
> Python scalars explicitly in lots of places.
This bit, for example, comes from the fact that most of the math on
scalars still uses ufuncs for their implementation. The numpy scalars
could definitely use some improvements.
However, I think my proposal for limited indexing capabilities should be
considered separately from coercion behavior of NumPy scalars. NumPy
scalars are intentionally different from Python scalars, and I see this
difference growing due to where Python itself is going. For example,
the int/long unification is going to change the ability for numpy.int to
inherit from int. I could also forsee the Python float being an
instance of a Decimal object or some other infinite precision float at
some point which would prevent inheritance for the numpy.float object.
The legitimate question is *how* different should they really be in each
More information about the Numpy-discussion