[Numpy-discussion] Behavior of array scalars

Travis Oliphant oliphant at ee.byu.edu
Fri Feb 17 16:54:05 CST 2006


Sasha wrote:

>It would be nice to collect the motivations behind the current state
>of affairs with rank-0 arrays in one place.  Due to the "hard-hat"
>nature of the issue, I would suggest to do it at
>http://projects.scipy.org/scipy/numpy/wiki/ZeroRankArray .
>
>Travis' Numeric3 design document actually leaves the issue open
>
>  
>
This document is old.  Please don't refer to it too stringently.   It 
reflected my thinking at the start of the project.  There are mailing 
list discussions that have more relevance.   The source reflects what 
was actually done.  What was done is introduce scalar array types for 
every data-type and return those.

I had originally thought that the pure Python user would *never* see 
rank-0 arrays.  That's why PyArray_Return is called all over the place 
in the code.  The concept that practicality beats purity won out and 
there are a few limited wasy you can get zero-dimensional arrays (i.e. 
using array(5) which used to return an array scalar).  They just don't 
*stay* 0-d arrays and are converted to array scalars at almost every 
opportunity....  I have been relaxing this over time, however.  

I can't say I have some grand understanding that is guiding the 
relaxation of this rule, however, except that I still think array 
scalars are *better* to deal with (I think this will be especially 
obvious when we get scalar math implemented).   So, I relunctantly give 
visibility to 0-d arrays when particular use-cases emerge.

>In any case I will collect all these thoughts on the ZeroRankArray
>page unless I hear that this belongs to the main wiki.
>  
>
It's a good start.   This particular use case of course is actually 
showing us a deeper flaw in our use of output arguments in the ufunc 
which needs changing.

-Travis







More information about the Numpy-discussion mailing list