Repository: scipy/scipy

Issue:
scipy.interpolate.interpn docstring example
<!-- 
Thank you for taking the time to file a bug report. 
Please fill in the fields below, deleting the sections that 
don't apply to your issue. You can view the final output
by clicking the preview button above.
Note: This is a comment, and won't appear in the output.
-->

My issue is about the example code for the scipy.interpolate.interpn function ( https://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.interpn.html ).  The np.meshgrid function switches the x and y dimension indexing, since it is set on "Cartesian" as default. The Example Code does not produce an Error, but might does not work as wanted either. The problem can be seen, when changing the x, y and z dimensions into not having equally many entries (see code below). The Problem can be solved by putting the x and y dimension into the right order:
```
values = np.swapaxes(value_func_3d(*np.meshgrid(*points)), 0, 1)
```
or by putting the meshgrid function into matrix indexing (‘ij’) (I don't know how, because of the "*points" as argument, I'm very new to python...).
Not a big bug but might help some people...



#### Reproducing code example:
<!-- 
If you place your code between the triple backticks below, 
it will be rendered as a code block. 
-->

```
from scipy.interpolate import interpn
import numpy as np
def value_func_3d(x, y, z):
    return 2 * x + 3 * y - z
x = np.linspace(0, 4, 5)
y = np.linspace(0, 5, 6)
z = np.linspace(0, 4, 5)
points = (x, y, z)
values = value_func_3d(*np.meshgrid(*points))
point = np.array([2.21, 3.12, 1.15])
print(interpn(points, values, point))
```

#### Error message:
<!-- If any, paste the *full* error message inside a code block
as above (starting from line Traceback)
-->

```
ValueError                                Traceback (most recent call last)
<ipython-input-15-1265e69368be> in <module>
     14 
     15 point = np.array([2, 3, 1])
---> 16 print(interpn(points, values, point))

E:\Programme\Anaconda\lib\site-packages\scipy\interpolate\interpolate.py in interpn(points, values, xi, method, bounds_error, fill_value)
   2632         if not values.shape[i] == len(p):
   2633             raise ValueError("There are %d points and %d values in "
-> 2634                              "dimension %d" % (len(p), values.shape[i], i))
   2635     grid = tuple([np.asarray(p) for p in points])
   2636 

ValueError: There are 5 points and 6 values in dimension 0
```

#### Scipy/Numpy/Python version information:
<!-- You can simply run the following and paste the result in a code block
```
1.4.1 1.18.1 sys.version_info(major=3, minor=7, micro=6, releaselevel='final', serial=0)
```
-->


Discussion:

Resolving patch:
diff --git a/scipy/interpolate/interpolate.py b/scipy/interpolate/interpolate.py
--- a/scipy/interpolate/interpolate.py
+++ b/scipy/interpolate/interpolate.py
@@ -2613,17 +2613,17 @@ def interpn(points, values, xi, method="linear", bounds_error=True,
     >>> from scipy.interpolate import interpn
     >>> def value_func_3d(x, y, z):
     ...     return 2 * x + 3 * y - z
-    >>> x = np.linspace(0, 5)
-    >>> y = np.linspace(0, 5)
-    >>> z = np.linspace(0, 5)
+    >>> x = np.linspace(0, 4, 5)
+    >>> y = np.linspace(0, 5, 6)
+    >>> z = np.linspace(0, 6, 7)
     >>> points = (x, y, z)
-    >>> values = value_func_3d(*np.meshgrid(*points))
+    >>> values = value_func_3d(*np.meshgrid(*points, indexing='ij'))
 
     Evaluate the interpolating function at a point
 
     >>> point = np.array([2.21, 3.12, 1.15])
     >>> print(interpn(points, values, point))
-    [11.72]
+    [12.63]
 
     See also
     --------


Test patch: