[Numpy-discussion] Matching 0-d arrays and NumPy scalars

Konrad Hinsen konrad.hinsen@laposte....
Thu Feb 21 10:47:56 CST 2008


On Feb 21, 2008, at 16:03, Travis E. Oliphant wrote:

> 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.

True, but this is almost an implementation detail.

What I see as more fundamental is the behaviour of Python container  
objects (lists, sets, etc.). If you add an object to a container and  
then access it as an element of the container, you get the original  
object (or something that behaves like the original object) without  
any trace of the container itself. I don't see why arrays should  
behave differently from all the other Python container objects -  
certainly not because it would be rather easy to implement.

NumPy has been inspired a lot by array languages like APL or Matlab.  
In those languages, everything is an array, and plain numbers that  
would be scalars elsewhere are considered 0-d arrays. Python is not  
an array language but an OO language with the more general concepts  
of containers, sequences, iterators, etc. Arrays are just one kind of  
container object among many others, so they should respect the common  
behaviours of containers.

Konrad.



More information about the Numpy-discussion mailing list