[SciPy-User] Return type of scipy.interpolate.splev for input array of length 1

Pauli Virtanen pav+sp at iki.fi
Tue Jan 19 04:41:23 EST 2010


Mon, 18 Jan 2010 10:59:46 -0500, josef.pktd wrote:
> On Sun, Jan 17, 2010 at 5:25 AM, Yves Frederix <yves.frederix at gmail.com>
> wrote:
[clip]
>> It was rather unexpected that the type of input and output data are
>> different. After checking interpolate/fitpack.py it seems that this
>> behavior results from the fact that the length-1 case is explicitly
>> treated differently (probably to be able to deal with the case of
>> scalar input, for which scalar output is expected):
>>
>>  434 def splev(x,tck,der=0):
>>  <snip>
>>  487         if ier: raise TypeError,"An error occurred" 488        
>>  if len(y)>1: return y 489         return y[0]
>>  490
>>
>> Wouldn't it be less confusing to have the return value always have the
>> same type as the input data?
> 
> I don't know of any "official" policy.

I think (unstructured) interpolation should respect

	input.shape == output.shape

also for 0-d. So yes, it's a wart, IMHO.

Another question is: how many people actually have code that depends on 
this wart, and can it be fixed? I'd guess there's not much problem: (1,) 
arrays function nicely as scalars, but not vice versa because of 
mutability.

-- 
Pauli Virtanen




More information about the SciPy-User mailing list