append versus resize for numpy array

Posted by Abruzzo Forte e Gentile on Stack Overflow See other posts from Stack Overflow or by Abruzzo Forte e Gentile
Published on 2010-05-25T21:30:11Z Indexed on 2010/05/25 21:51 UTC
Read the original article Hit count: 205

Filed under:

Hi all

I would like to append a value at the end of my numpy.array. I saw numpy.append function but this performs an exact copy of the original array adding at last my new value. I would like to avoid copies since my arrays are big.

I am using resize method and then set the last index available to the new value. Can you confirm that resize is the best way to append a value at the end? Is it not moving memory around someway?

Thanks AFG

oldSize = myArray,shape(0)
myArray.resize( oldSize + 1 )
myArray[oldSize] = newValue

© Stack Overflow or respective owner

Related posts about numpy