[Numpy-discussion] Counting array elements

Chris Barker Chris.Barker at noaa.gov
Mon Nov 1 15:35:24 CST 2004

Perry Greenfield wrote:
> This aspect of flat can be considered a wart. There are three different
> desired behaviors depending on who you talk to. For efficiency reasons,
> some only want flat (and even ravel) to work if the array is already
> contiguous; that is, they don't want copies unless they ask for them.

This isn't just efficiency: having a function (or method) that sometimes 
returns a copy, and sometimes a reference is asking for bugs. What 
happens if I make a change to the result in a function? Sometimes it 
will change the parent array, sometimes not.

> otherwise for it to return a view. Yet others always want a copy.
> So, are three different versions needed? Or options to a function?
> The drawback of .flat (as an attribute) is there is only one choice
> for behavior.

A agree. I vote for a method.

By the way, is it really impossible to have a discontiguous 1-d array? 
I'm not wizard at C or C++ but I've worked with the Numeric api enough 
to see what the problem is. However, it seems that there should be way 
to have a "get the n-th element" function or method to the Numarray 
object that should then work on polymorphic types, one of which would be 
a rank-1 non-contiguous array. Perhaps there is way too much existing 
code that relies on the array->strides[n] approach to introduce this 
now, but I think this kind of thing would be the key to making it easier 
to write optimized Numarray functions.

> I'd
> very much prefer not proliferate any more flavors of behavior
> and just settle on one.

+5 on this. I'd really like SciPy and numarray both to have the goal of 
merging the two.


Christopher Barker, Ph.D.
NOAA/OR&R/HAZMAT         (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov

More information about the Numpy-discussion mailing list