<p dir="auto">interpn returns nan when one of the dimensions of the grid has length 1, even if the inputs are perfectly valid.  I know this is an edge case, but it's crucial to my program, and working around it requires ugly hacks.</p>
<h3 dir="auto">Reproducing code example:</h3>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="values = np.array([0.1,1,10]).reshape((1,3))
xi = np.array([[1, 2.2], [1, 3.2], [1, 3.8]])
print(scipy.interpolate.interpn(([1], [2,3,4]), values, xi))"><pre class="notranslate"><code class="notranslate">values = np.array([0.1,1,10]).reshape((1,3))
xi = np.array([[1, 2.2], [1, 3.2], [1, 3.8]])
print(scipy.interpolate.interpn(([1], [2,3,4]), values, xi))
</code></pre></div>
<h3 dir="auto">Error message:</h3>

<p dir="auto">No error message, but returns array([nan, nan, nan])</p>
<h3 dir="auto">Scipy/Numpy/Python version information:</h3>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="1.1.0 1.15.1 sys.version_info(major=3, minor=7, micro=0, releaselevel='final', serial=0)"><pre class="notranslate"><code class="notranslate">1.1.0 1.15.1 sys.version_info(major=3, minor=7, micro=0, releaselevel='final', serial=0)
</code></pre></div>
<p dir="auto">The documentation for the <a href="https://docs.scipy.org/doc/scipy-0.19.1/reference/generated/scipy.interpolate.RegularGridInterpolator.html" rel="nofollow">RegularGridInterpolator</a> states that if the <code class="notranslate">bounds_error</code> is set to False the <code class="notranslate">fill_value</code> is used. And if the <code class="notranslate">fill_value</code> is None, the values are extrapolated.</p>
<p dir="auto">However, in the case of a dimensions with length 1, this doesn't seem to apply. Interpolating and extrapolating with 1 value is certainly an edge case. But based on the documentation i would expect (correct me if i'm wrong), that extrapolating or interpolating with 1 value will yield that same value.</p>
<p dir="auto">The current implementation results in <code class="notranslate">nan</code> values. The difficulty is that if you cant be sure that all data dimensions are n&gt;1, you have to check this and slice out those dimensions, and change the call to the <code class="notranslate">Interpolator</code> to exclude those parameters.</p>
<h3 dir="auto">Reproducing code example:</h3>
<p dir="auto">This doesnt work:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="from scipy.interpolate import RegularGridInterpolator
import numpy as np

def f(x,y):    
    return (y+1) * x

x = np.array([0, 5., 10])
y = np.array([0.])

data = f(*np.meshgrid(x,y, indexing='ij', sparse=True))
# data = array([[  0.], [  5.], [ 10.]])

my_interp = RegularGridInterpolator((x, y), data, fill_value=None, bounds_error=False)
my_interp((5.0, 0.))

output[4]: array(nan)"><pre class="notranslate"><span class="pl-k">from</span> <span class="pl-s1">scipy</span>.<span class="pl-s1">interpolate</span> <span class="pl-k">import</span> <span class="pl-v">RegularGridInterpolator</span>
<span class="pl-k">import</span> <span class="pl-s1">numpy</span> <span class="pl-k">as</span> <span class="pl-s1">np</span>

<span class="pl-k">def</span> <span class="pl-en">f</span>(<span class="pl-s1">x</span>,<span class="pl-s1">y</span>):    
    <span class="pl-k">return</span> (<span class="pl-s1">y</span><span class="pl-c1">+</span><span class="pl-c1">1</span>) <span class="pl-c1">*</span> <span class="pl-s1">x</span>

<span class="pl-s1">x</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">array</span>([<span class="pl-c1">0</span>, <span class="pl-c1">5.</span>, <span class="pl-c1">10</span>])
<span class="pl-s1">y</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">array</span>([<span class="pl-c1">0.</span>])

<span class="pl-s1">data</span> <span class="pl-c1">=</span> <span class="pl-en">f</span>(<span class="pl-c1">*</span><span class="pl-s1">np</span>.<span class="pl-en">meshgrid</span>(<span class="pl-s1">x</span>,<span class="pl-s1">y</span>, <span class="pl-s1">indexing</span><span class="pl-c1">=</span><span class="pl-s">'ij'</span>, <span class="pl-s1">sparse</span><span class="pl-c1">=</span><span class="pl-c1">True</span>))
<span class="pl-c"># data = array([[  0.], [  5.], [ 10.]])</span>

<span class="pl-s1">my_interp</span> <span class="pl-c1">=</span> <span class="pl-v">RegularGridInterpolator</span>((<span class="pl-s1">x</span>, <span class="pl-s1">y</span>), <span class="pl-s1">data</span>, <span class="pl-s1">fill_value</span><span class="pl-c1">=</span><span class="pl-c1">None</span>, <span class="pl-s1">bounds_error</span><span class="pl-c1">=</span><span class="pl-c1">False</span>)
<span class="pl-en">my_interp</span>((<span class="pl-c1">5.0</span>, <span class="pl-c1">0.</span>))

<span class="pl-s1">output</span>[<span class="pl-c1">4</span>]: <span class="pl-en">array</span>(<span class="pl-s1">nan</span>)</pre></div>
<p dir="auto">But adding a value to <code class="notranslate">y</code> makes it work:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="y = np.array([0., 1.0])

data = f(*np.meshgrid(x,y, indexing='ij', sparse=True))
# data = array([[  0.,   0.], [  5.,  10.], [ 10.,  20.]])

my_interp = RegularGridInterpolator((x, y), data, fill_value=None, bounds_error=False)
my_interp([5.0, 0.])

output[5]: array([ 5.])"><pre class="notranslate"><span class="pl-s1">y</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">array</span>([<span class="pl-c1">0.</span>, <span class="pl-c1">1.0</span>])

<span class="pl-s1">data</span> <span class="pl-c1">=</span> <span class="pl-en">f</span>(<span class="pl-c1">*</span><span class="pl-s1">np</span>.<span class="pl-en">meshgrid</span>(<span class="pl-s1">x</span>,<span class="pl-s1">y</span>, <span class="pl-s1">indexing</span><span class="pl-c1">=</span><span class="pl-s">'ij'</span>, <span class="pl-s1">sparse</span><span class="pl-c1">=</span><span class="pl-c1">True</span>))
<span class="pl-c"># data = array([[  0.,   0.], [  5.,  10.], [ 10.,  20.]])</span>

<span class="pl-s1">my_interp</span> <span class="pl-c1">=</span> <span class="pl-v">RegularGridInterpolator</span>((<span class="pl-s1">x</span>, <span class="pl-s1">y</span>), <span class="pl-s1">data</span>, <span class="pl-s1">fill_value</span><span class="pl-c1">=</span><span class="pl-c1">None</span>, <span class="pl-s1">bounds_error</span><span class="pl-c1">=</span><span class="pl-c1">False</span>)
<span class="pl-en">my_interp</span>([<span class="pl-c1">5.0</span>, <span class="pl-c1">0.</span>])

<span class="pl-s1">output</span>[<span class="pl-c1">5</span>]: <span class="pl-en">array</span>([ <span class="pl-c1">5.</span>])</pre></div>
<h3 dir="auto">Error message:</h3>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="C:\Miniconda3\envs\py36\lib\site-packages\scipy\interpolate\interpolate.py:2467: RuntimeWarning: invalid value encountered in true_divide
  (grid[i + 1] - grid[i]))"><pre class="notranslate"><code class="notranslate">C:\Miniconda3\envs\py36\lib\site-packages\scipy\interpolate\interpolate.py:2467: RuntimeWarning: invalid value encountered in true_divide
  (grid[i + 1] - grid[i]))
</code></pre></div>
<h3 dir="auto">Scipy/Numpy/Python version information:</h3>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="0.19.0 1.12.1 sys.version_info(major=3, minor=6, micro=1, releaselevel='final', serial=0)"><pre class="notranslate"><code class="notranslate">0.19.0 1.12.1 sys.version_info(major=3, minor=6, micro=1, releaselevel='final', serial=0)
</code></pre></div>