[Numpy-discussion] appending extra items to arrays
Chad Kidder
cckidder at gmail.com
Wed Oct 17 08:58:50 EDT 2007
Growing an array by appending it is the slow way in matlab. The
suggested way to do things there is preallocate the array by saying
x=zeros(....) and then referencing the elements in the array and
inserting the correct value.
--Chad Kidder
On Oct 17, 2007, at 7:16 AM, mark wrote:
> So it seems like lists are the way to grow an array.
>
> Interestingly enough, it is very easy to grown an array in Matlab.
> Any idea how they do that (or are they slow as well?).
>
> Mark
>
> On Oct 11, 8:53 pm, "Adam Mercer" <ramer... at gmail.com> wrote:
>> On 11/10/2007, Mark Janikas <mjani... at esri.com> wrote:
>>
>>> If you do not know the size of your array before you finalize it,
>>> then
>>> you should use lists whenever you can. I just cooked up a short
>>> example:
>>
>> <snip>
>>
>>> ##### Result #####
>>> Total Time with array: 2.12951189331
>>> Total Time with list: 0.0469707035741
>>> ####################################################################
>>> ####
>>> ####
>>
>>> Hope this helps,
>>
>> That is helpful, I thought that using arrays would be much faster but
>> its clearly not in this case.
>>
>> Thanks
>>
>> Adam
>> _______________________________________________
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20071017/87df94e6/attachment.html>
More information about the NumPy-Discussion
mailing list