summaryrefslogtreecommitdiff
path: root/numpy/lib/function_base.py
diff options
context:
space:
mode:
authornjsmith <njs@pobox.com>2012-09-11 11:07:32 -0700
committernjsmith <njs@pobox.com>2012-09-11 11:07:32 -0700
commitaed8fc547bfac6f3d9248e65a53e3eae6393a715 (patch)
treebcb8c82703bbebdb789746a2a8b5622c9a2185ae /numpy/lib/function_base.py
parentb6a1acdd6c989e6e2ab6d68f1b60af030bcccc49 (diff)
parent1688b29fb1ea4e548762ae79522c50abce88d55b (diff)
downloadnumpy-aed8fc547bfac6f3d9248e65a53e3eae6393a715.tar.gz
Merge pull request #429 from 87/fix_insert
Fix for issues #392 and #378
Diffstat (limited to 'numpy/lib/function_base.py')
-rw-r--r--numpy/lib/function_base.py14
1 files changed, 8 insertions, 6 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py
index 247f16560..2b1d780d2 100644
--- a/numpy/lib/function_base.py
+++ b/numpy/lib/function_base.py
@@ -3591,19 +3591,21 @@ def insert(arr, obj, values, axis=None):
slobj = [slice(None)]*ndim
N = arr.shape[axis]
newshape = list(arr.shape)
- if isinstance(obj, (int, long, integer)):
+ 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))
-
- if isinstance(values, (int, long, integer)):
- obj = [obj]
+ if isscalar(values):
+ obj = [obj]
else:
- obj = [obj] * len(values)
-
+ values = asarray(values)
+ if ndim > values.ndim:
+ obj = [obj]
+ else:
+ obj = [obj] * len(values)
elif isinstance(obj, slice):
# turn it into a range object