[Numpy-discussion] The array interface published

Robert Kern rkern at ucsd.edu
Wed Apr 6 03:36:51 EDT 2005


Magnus Lie Hetland wrote:

> So -- at *least* adding the array protocol to it would be doing it a
> favour, i.e., making it a useful module, and sort of a prototypical
> example of the protocol and such. Adding more dimensions might simply
> make it more useful. (I've many times been asked by people how to
> create e.g. two-dimensional arrays in Python. It would be nice if
> there was actually some basic support for it.)

Re-implementing the stdlib-array module to support multiple dimensions 
is almost certainly a non-starter. You can't easily do it without 
breaking its pre-allocation strategy. It preallocates memory for 
elements using the same algorithm that lists do, so .append() has 
reasonable amortized time behaviour.

python-dev will not appreciate changing the algorithmic complexity of a 
long-existing component to accomodate a half-arsed implementation of N-D 
arrays.

OTOH, it is the one reason for stdlib-array's use in a Numeric world: 
sometimes, you just need to append values; you can't pre-allocate with 
Numeric.empty() and index in values. Using stdlib-array to collect the 
values, then using the buffer interface (soon-to-be __array__ interface) 
to convert to a Numeric array is faster than the alternatives.

-- 
Robert Kern
rkern at ucsd.edu

"In the fields of hell where the grass grows high
  Are the graves of dreams allowed to die."
   -- Richard Harter




More information about the NumPy-Discussion mailing list