[Scipy-tickets] [SciPy] #660: interp1d - wrong shaping behaviour

SciPy scipy-tickets@scipy....
Fri May 2 04:43:46 CDT 2008


#660: interp1d - wrong shaping behaviour
-------------------------------+--------------------------------------------
 Reporter:  djkawa             |       Owner:  somebody
     Type:  defect             |      Status:  new     
 Priority:  normal             |   Milestone:  0.7     
Component:  scipy.interpolate  |     Version:          
 Severity:  normal             |    Keywords:          
-------------------------------+--------------------------------------------
 Hi,

 my setup is python 2.4.4
 scipy 0.6.0
 numpy 1.0.3.1 (there are some bugs we have reported in 1.0.4 so we cannot
 use it)

 I am using the scipy.interpolate.interp1d class quite extensively and
 there are two shaping behaviours that i don't understand:

 1 - is simple:
 why when you interp on a x_new which is a scalar, the y_new is not a
 scalar as well but a 1d array instead?

 2 - is a bit more brain consuming for my array visualization skills:
 when axis = 0 and the dimension of y is greater than 2, i would expect
 something else. see my example:

 {{{
 >>> import scipy
 >>> from scipy import *
 >>> from scipy.interpolate import interp1d
 >>> aa = array([[0.,10.,20.],[30.,40.,50.]])
 >>> bb = 10 + aa
 >>> cc = 10 + bb
 >>> dd = array([aa,bb,cc])
 >>> ee = 10 + dd

 >>> aa
 array([[  0.,  10.,  20.],
        [ 30.,  40.,  50.]])
 >>> bb
 array([[ 10.,  20.,  30.],
        [ 40.,  50.,  60.]])
 >>> ii = interp1d([0.,1.], [aa, bb], axis = 0)
 >>> ii([0.1,0.5])
 array([[[  1.,  31.],
         [ 11.,  41.],
         [ 21.,  51.]],

        [[  5.,  35.],
         [ 15.,  45.],
         [ 25.,  55.]]])
 >>> ii([0.1,0.5]).swapaxes(-1,-2)
 array([[[  1.,  11.,  21.],
         [ 31.,  41.,  51.]],

        [[  5.,  15.,  25.],
         [ 35.,  45.,  55.]]])
 >>> dd
 array([[[  0.,  10.,  20.],
         [ 30.,  40.,  50.]],

        [[ 10.,  20.,  30.],
         [ 40.,  50.,  60.]],

        [[ 20.,  30.,  40.],
         [ 50.,  60.,  70.]]])
 >>> ee
 array([[[ 10.,  20.,  30.],
         [ 40.,  50.,  60.]],

        [[ 20.,  30.,  40.],
         [ 50.,  60.,  70.]],

        [[ 30.,  40.,  50.],
         [ 60.,  70.,  80.]]])
 >>> ii = interp1d([0.,1.], [dd, ee], axis = 0)
 >>> ii([0.1,0.5])
 array([[[[  1.,  31.],
          [ 11.,  41.],
          [ 21.,  51.]],

         [[ 11.,  41.],
          [ 21.,  51.],
          [ 31.,  61.]],

         [[ 21.,  51.],
          [ 31.,  61.],
          [ 41.,  71.]]],


        [[[  5.,  35.],
          [ 15.,  45.],
          [ 25.,  55.]],

         [[ 15.,  45.],
          [ 25.,  55.],
          [ 35.,  65.]],

         [[ 25.,  55.],
          [ 35.,  65.],
          [ 45.,  75.]]]])
 >>> ii([0.1,0.5]).swapaxes(-1,-2)
 array([[[[  1.,  11.,  21.],
          [ 31.,  41.,  51.]],

         [[ 11.,  21.,  31.],
          [ 41.,  51.,  61.]],

         [[ 21.,  31.,  41.],
          [ 51.,  61.,  71.]]],


        [[[  5.,  15.,  25.],
          [ 35.,  45.,  55.]],

         [[ 15.,  25.,  35.],
          [ 45.,  55.,  65.]],

         [[ 25.,  35.,  45.],
          [ 55.,  65.,  75.]]]])
 }}}

 in both cases, as you might have guessed, i would expect the "swapaxes"
 answer. is there a good reason not to have it or is it a bug?

 thanks for your reply.

 gilles

-- 
Ticket URL: <http://scipy.org/scipy/scipy/ticket/660>
SciPy <http://www.scipy.org/>
SciPy is open-source software for mathematics, science, and engineering.


More information about the Scipy-tickets mailing list