[Numpy-discussion] Resize method

Christopher Barker Chris.Barker@noaa....
Mon Nov 23 14:10:53 CST 2009

Colin J. Williams wrote:
> Access by the interpreter prevents array resizing.

yup -- resize is really fragile for that reason. It really should be 
used quite sparingly.

Personally, I think it should probably only be used when wrapped with a 
higher level layer.

I've been working on an extendable array class, I call an accumulator 
(bad name...). The idea is that you can use it to accumulate values when 
you don't know how big it's going to end up, rather than using a list 
for this, which is the standard idiom.

In [2]: import accumulator

In [3]: a = accumulator.accumulator((1,2,3,4,))

In [4]: a
Out[4]: accumulator([1, 2, 3, 4])

In [5]: a.append(5)

In [6]: a
Out[6]: accumulator([1, 2, 3, 4, 5])

In [8]: a.extend((6,7,8,9))
In [9]: a
Out[9]: accumulator([1, 2, 3, 4, 5, 6, 7, 8, 9])

At the moment, it only support 1-d arrays, though I'd like to extend it 
to n-d, probably only allowing growing on the first axis.

This has been discussed on this list a fair bit, with mixed reviews as 
to whether there is any point. It's slower than lists in common usage, 
but has other advantages -- I'd like to see a C version, but don't know 
if I'll ever have the time for that.

I've enclosed to code for your viewing pleasure


Christopher Barker, Ph.D.

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

-------------- next part --------------
A non-text attachment was scrubbed...
Name: Accumulator.zip
Type: application/zip
Size: 5184 bytes
Desc: not available
Url : http://mail.scipy.org/pipermail/numpy-discussion/attachments/20091123/bc77171e/attachment.zip 

More information about the NumPy-Discussion mailing list