behavior of 'insert' for inserting multiple values

Hello list. When I try to insert multiple values in one place, I want to do this:
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.])
Wouldn't it make sense if the first example works as well? Mark

Hi Mark 2008/5/27 mark <markbak@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

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

mark wrote:
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,
If you file a ticket, this request is less likely to be lost or forgotten. Thanks for the testing and feedback. Best regards, -Travis
participants (3)
-
mark
-
Stéfan van der Walt
-
Travis E. Oliphant