[Numpy-discussion] numpy.append & numpy.where vs list.append and brute iterative for loop
Christopher Barker
Chris.Barker at noaa.gov
Thu Jan 27 18:33:36 EST 2011
On 1/27/11 1:53 PM, Sturla Molden wrote:
> But N appends are O(N) for lists and O(N*N) for arrays.
hmmm - that doesn't seem quite right -- lists still have to re-allocate
and copy, they just do it every n times (where n grows with the list),
so I wouldn't expect exactly O(N).
But you never know 'till you profile. See the enclosed code and figures.
Interestingly both appear to be pretty linear, though the constant is
Much larger for numpy arrays.
-Chris
--
Christopher Barker, Ph.D.
Oceanographer
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
Chris.Barker at noaa.gov
-------------- next part --------------
A non-text attachment was scrubbed...
Name: append_time.py
Type: application/x-python
Size: 1006 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20110127/8958f853/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: append_timing.png
Type: image/png
Size: 40428 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20110127/8958f853/attachment.png>
More information about the NumPy-Discussion
mailing list