clean way prepend an element to a numpy array

bdb112 boyd.blackwell at gmail.com
Tue Jul 21 01:41:13 EDT 2009


On Jul 21, 2:13 pm, Ben Finney <ben+pyt... at benfinney.id.au> wrote:
> bdb112 <boyd.blackw... at gmail.com> writes:
> > If I want to add an element at the beginning of an array, it seems
> > like I must make a list, insert in place, then make an array again.
>
> The NumPy ‘ndarray’ type (which is what you get by default from the
> ‘array’ factory function) is a far more complex type than (and is not
> derived from) the Python list.
>
> For manipulating them, you'll want to study the NumPy documentation
> <URL:http://docs.scipy.org/doc/numpy/reference/arrays.ndarray.html>.
>

Yes, I had had a look through that - nothing there that allows writing
a succint
clear statement (except for my .resize example in the original post),
although if efficiency was
a concern, then maybe resize and shift right, but that would really
obscure the code.




More information about the Python-list mailing list