From 926564c195d30542312123b7d76fe091c3453881 Mon Sep 17 00:00:00 2001 From: Han Genuit Date: Fri, 7 Sep 2012 01:27:58 +0200 Subject: BUG: Fix for issues #378 and #392 This should fix the problems with numpy.insert(), where the input values were not checked for all scalar types and where values did not get inserted properly, but got duplicated by default. --- numpy/lib/function_base.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'numpy/lib/function_base.py') 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 -- cgit v1.2.1