<p dir="auto"><em>Original ticket <a href="http://projects.scipy.org/scipy/ticket/660" rel="nofollow">http://projects.scipy.org/scipy/ticket/660</a> on 2008-05-02 by trac user djkawa, assigned to unknown.</em></p>
<p dir="auto">Hi,</p>
<p dir="auto">my setup is python 2.4.4<br>
scipy 0.6.0<br>
numpy 1.0.3.1 (there are some bugs we have reported in 1.0.4 so we cannot use it)</p>
<p dir="auto">I am using the scipy.interpolate.interp1d class quite extensively and there are two shaping behaviours that i don't understand:</p>
<p dir="auto">1 - is simple:<br>
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?</p>
<p dir="auto">2 - is a bit more brain consuming for my array visualization skills:<br>
when axis = 0 and the dimension of y is greater than 2, i would expect something else. see my example:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; import scipy
&gt;&gt;&gt; from scipy import *
&gt;&gt;&gt; from scipy.interpolate import interp1d
&gt;&gt;&gt; aa = array([[0.,10.,20.],[30.,40.,50.]])
&gt;&gt;&gt; bb = 10 + aa
&gt;&gt;&gt; cc = 10 + bb
&gt;&gt;&gt; dd = array([aa,bb,cc])
&gt;&gt;&gt; ee = 10 + dd

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

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

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

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

       [[ 20.,  30.,  40.],
        [ 50.,  60.,  70.]]])
&gt;&gt;&gt; ee
array([[[ 10.,  20.,  30.],
        [ 40.,  50.,  60.]],

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

       [[ 30.,  40.,  50.],
        [ 60.,  70.,  80.]]])
&gt;&gt;&gt; ii = interp1d([0.,1.], [dd, ee], axis = 0)
&gt;&gt;&gt; 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.]]]])
&gt;&gt;&gt; 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.]]]])"><pre class="notranslate"><code class="notranslate">&gt;&gt;&gt; import scipy
&gt;&gt;&gt; from scipy import *
&gt;&gt;&gt; from scipy.interpolate import interp1d
&gt;&gt;&gt; aa = array([[0.,10.,20.],[30.,40.,50.]])
&gt;&gt;&gt; bb = 10 + aa
&gt;&gt;&gt; cc = 10 + bb
&gt;&gt;&gt; dd = array([aa,bb,cc])
&gt;&gt;&gt; ee = 10 + dd

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

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

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

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

       [[ 20.,  30.,  40.],
        [ 50.,  60.,  70.]]])
&gt;&gt;&gt; ee
array([[[ 10.,  20.,  30.],
        [ 40.,  50.,  60.]],

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

       [[ 30.,  40.,  50.],
        [ 60.,  70.,  80.]]])
&gt;&gt;&gt; ii = interp1d([0.,1.], [dd, ee], axis = 0)
&gt;&gt;&gt; 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.]]]])
&gt;&gt;&gt; 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.]]]])
</code></pre></div>
<p dir="auto">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?</p>
<p dir="auto">thanks for your reply.</p>
<p dir="auto">gilles</p>
<p dir="auto"><em>Original ticket <a href="http://projects.scipy.org/scipy/ticket/289" rel="nofollow">http://projects.scipy.org/scipy/ticket/289</a> on 2006-10-17 by trac user Fruny, assigned to <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/rkern/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/rkern">@rkern</a>.</em></p>
<p dir="auto">When the interpolation is done on the first axis, the other axes get transposed in the output.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="from numpy import *
from scipy.interpolate import interp1d

Y = arange(5*7*11*13).reshape(5,7,11,13)
X = arange(5)
print interp1d(X,Y,axis=0)(X).shape     # Get (5,13,11,7), expected (5,7,11,13)

X = arange(7)
print interp1d(X,Y,axis=1)(X).shape     # Get (5,7,11,13) as expected

X = arange(11)
print interp1d(X,Y,axis=2)(X).shape     # Get (5,7,11,13) as expected

X = arange(13)
print interp1d(X,Y,axis=3)(X).shape     # Get (5,7,11,13) as expected"><pre class="notranslate"><code class="notranslate">from numpy import *
from scipy.interpolate import interp1d

Y = arange(5*7*11*13).reshape(5,7,11,13)
X = arange(5)
print interp1d(X,Y,axis=0)(X).shape     # Get (5,13,11,7), expected (5,7,11,13)

X = arange(7)
print interp1d(X,Y,axis=1)(X).shape     # Get (5,7,11,13) as expected

X = arange(11)
print interp1d(X,Y,axis=2)(X).shape     # Get (5,7,11,13) as expected

X = arange(13)
print interp1d(X,Y,axis=3)(X).shape     # Get (5,7,11,13) as expected
</code></pre></div>