summaryrefslogtreecommitdiff
path: root/numpy/lib/function_base.py
diff options
context:
space:
mode:
authorLoftie Ellis <lpellis@gmail.com>2012-07-10 17:20:53 -0400
committerEric Fode <ericfode@gmail.com>2012-07-15 00:19:17 -0400
commit2c04244da264cb1665d6162ae119d2f05ad65150 (patch)
treebe94c58ea3b2e9cd5449f097d28a819242d8f826 /numpy/lib/function_base.py
parent143fb1874b3ff3875a93accad3e87056a44d77d0 (diff)
downloadnumpy-2c04244da264cb1665d6162ae119d2f05ad65150.tar.gz
BUG: Ticket #808: Insert was not performing properly when an integer was
the argument passed to be used as the item to be insterted, and a list was passed as the positions. This was fixed by simply duplicating the item to be inserted so that it was a list of equal length and then control was passed to the already exsisting code to handel this case
Diffstat (limited to 'numpy/lib/function_base.py')
-rw-r--r--numpy/lib/function_base.py20
1 files changed, 7 insertions, 13 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py
index a0781ebf9..f0267afb4 100644
--- a/numpy/lib/function_base.py
+++ b/numpy/lib/function_base.py
@@ -3519,24 +3519,18 @@ def insert(arr, obj, values, axis=None):
N = arr.shape[axis]
newshape = list(arr.shape)
if isinstance(obj, (int, long, integer)):
+
if (obj < 0): obj += N
if obj < 0 or obj > N:
raise ValueError(
"index (%d) out of range (0<=index<=%d) "\
"in dimension %d" % (obj, N, axis))
- newshape[axis] += 1;
- new = empty(newshape, arr.dtype, arr.flags.fnc)
- slobj[axis] = slice(None, obj)
- new[slobj] = arr[slobj]
- slobj[axis] = obj
- new[slobj] = values
- slobj[axis] = slice(obj+1,None)
- slobj2 = [slice(None)]*ndim
- slobj2[axis] = slice(obj,None)
- new[slobj] = arr[slobj2]
- if wrap:
- return wrap(new)
- return new
+
+ if isinstance(values, (int, long, integer)):
+ obj = [obj]
+ else:
+ obj = [obj] * len(values)
+
elif isinstance(obj, slice):
# turn it into a range object