[Numpy-discussion] RE: default axis for numarray

Paul Barrett Barrett at stsci.edu
Wed Jun 12 08:55:05 CDT 2002


eric jones wrote:

> 
> I think the consistency with Python is less of an issue than it seems.
> I wasn't aware that add.reduce(x) would generated the same results as
> the Python version of reduce(add,x) until Perry pointed it out to me.
> There are some inconsistencies between Python the language and Numeric
> because the needs of the Numeric community.  For instance, slices create
> views instead of copies as in Python.  This was a correct break with
> consistency in a very utilized area of Python because of efficiency.  

<Begin Rant>

I think consistency is an issue, particularly for novices.  You cite the issue 
of slices creating views instead of copies as being the correct choice.  But 
this decision is based solely on the perception that views are 'inherently' more 
efficient than copies and not on reasons of consistency or usability.  I (a 
seasoned user) find view behavior to be annoying and have been caught out on 
this several times.  For example, reversing in-place the elements of any array 
using slices, i.e. A = A[::-1], will give the wrong answer, unless you 
explicitly make a copy before doing the assignment.  Whereas, copy behavior will 
do the right thing.  I suggest that many novices will be caught out by this and 
similar examples, as I have been.  Copy behavior for slices can be just as 
efficient as view behavior, if implemented as copy-on-write.

The beauty of Python is that it allows the developer to spend much more time on 
consistency and usability issues than on implementation issues.  Sadly, I think 
much of Numeric development is based solely on implementation issues to the 
detriment of consistency and usability.

I don't have enough experience to definitely say whether axis=0 should be 
preferred over axis=-1 or vice versa. But is does appear that for the most 
general cases axis=0 is probably preferred.  This is the default for the APL and 
J programming of which Numeric is based.  Should we not continue to follow their 
lead?  It might be nice to see a list of examples where axis=0 is the preferred 
default and the same for axis=-1.

<End Rant>


-- 
Paul Barrett, PhD      Space Telescope Science Institute
Phone: 410-338-4475    ESS/Science Software Group
FAX:   410-338-4767    Baltimore, MD 21218





More information about the Numpy-discussion mailing list