From 50fad03b2ab81d9518e95138f2425ecd82740be3 Mon Sep 17 00:00:00 2001 From: Sebastian Berg Date: Mon, 2 Dec 2013 13:47:46 +0100 Subject: BUG: Fix np.insert with negative axis. In some cases a negative axis argument to np.insert would result in wrong behaviour due to np.rollaxis, add modulo operation to avoid this (an error is still raised due to arr.shape[axis]). Closes gh-3494 --- numpy/lib/function_base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'numpy/lib/function_base.py') diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py index 9176d9950..db0c5ffbb 100644 --- a/numpy/lib/function_base.py +++ b/numpy/lib/function_base.py @@ -3607,7 +3607,7 @@ def insert(arr, obj, values, axis=None): # broadcasting is very different here, since a[:,0,:] = ... behaves # very different from a[:,[0],:] = ...! This changes values so that # it works likes the second case. (here a[:,0:1,:]) - values = np.rollaxis(values, 0, axis + 1) + values = np.rollaxis(values, 0, (axis % values.ndim) + 1) numnew = values.shape[axis] newshape[axis] += numnew new = empty(newshape, arr.dtype, arr.flags.fnc) -- cgit v1.2.1