[Numpy-discussion] behavior of 'insert' for inserting multiple values

mark markbak@gmail....
Fri May 30 10:01:42 CDT 2008


I think this is a special case that was overlooked.
It works if there are multiple positions but only one value:
>>> a = arange(5)
>>> insert(a,[3,3],4)
array([0, 1, 2, 4, 4, 3, 4])

But not when you give one position with mutiple values:
>>> insert(a,3,[7,7])
array([0, 1, 2, 7, 3, 4])

It would be great if somebody could implement this.
Probably not too hard I guess,
Thanks. You guys are the best,
Mark

On May 27, 11:26 am, "Stéfan van der Walt" <ste...@sun.ac.za> wrote:
> Hi Mark
>
> 2008/5/27 mark <mark...@gmail.com>:
>
> >>>> a = arange(5.)
> >>>> insert(a,3,[7,7])
> > array([ 0.,  1.,  2.,  7.,  3.,  4.])
>
> > But insert only inserts one of the 7's, while I want both values to be
> > inserted. Nor does numpy throw a warning (which I think would be
> > appropriate). The way that works correctly is
>
> >>>> insert(a,[3,3],[7,7])
> > array([ 0.,  1.,  2.,  7.,  7.,  3.,  4.])
>
> You need to specify two insertion positions, i.e.
>
> np.insert(a, [3, 3], [7, 7])
>
> I think we should consider a special case for your example, though.
>
> Regards
> Stéfan
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discuss...@scipy.orghttp://projects.scipy.org/mailman/listinfo/numpy-discussion


More information about the Numpy-discussion mailing list