title: Why does RegularGridInterpolatior use so much more memory than a NearestNeighbourInterpolator?
body: <p>I have a function that creates a regular grid interpolator and then another function that creates a nearest-neighbour interpolator on a fine mesh of the regular grid interpolator. I was expecting the nearest-neighbour interpolator to be faster at interpolation, which it is, but it also uses much lower memory. Why is this?</p>
  <p>For example, I created a 6-Dimension regular grid of lengths 10 in each dimension and then converted that regular grid interpolator into a nearest neighbour interpolator. The regular grid interpolator used 8000873 bytes whereas the nearest neighbour used 1846 bytes.</p>
  <p>Even if I create a finer-mesh nearest neighbour interpolator by interpolating on a mesh 1000x as fine, the nearest neighbour interpolator still only uses 1268100 bytes. I will need to make the mesh 6500x as fine before the memory size is roughly equivalent.</p>
  <pre class="lang-py prettyprint-override"><code>import numpy as np
  from scipy.interpolate import RegularGridInterpolator, NearestNDInterpolator
  import pickle
  
  def create_RGI(dims):
      data = [np.linspace(0, 1, n) for n in dims]
      DATA = np.meshgrid(*data, indexing='ij', sparse=True)
      z = np.sum(DATA, axis=0)
      RGI = RegularGridInterpolator(data, z)
      return RGI
  
  def RGI_to_NNDI(RGI, factor=100):
      lims = [(x.min(), x.max()) for x in RGI.__dict__['grid']]
      lens = [len(x) for x in RGI.__dict__['grid']]
      data = [np.linspace(low, high, max(lens)*factor) for (low, high), l in zip(lims, lens)]
      DATA = np.meshgrid(*data, indexing='ij', sparse=True)
      z = RGI(np.vstack(list(map(np.ravel, DATA))).T)
      NNDI = NearestNDInterpolator(np.array(list(map(np.ravel, DATA))).T, z)
      return NNDI
  
  factor = 1
  RGI = create_RGI([10, 10, 10, 10, 10, 10])
  NNDI = RGI_to_NNDI(RGI, factor=factor)
  
  print((f&quot;&quot;&quot;
         Factor: {factor},
         RGI: {len(pickle.dumps(RGI))}, 
         NNDI: {len(pickle.dumps(NNDI))}&quot;&quot;&quot;))
  
  factor = 6500
  RGI = create_RGI([10, 10, 10, 10, 10, 10])
  NNDI = RGI_to_NNDI(RGI, factor=factor)
  
  print((f&quot;&quot;&quot;
         Factor: {factor},
         RGI: {len(pickle.dumps(RGI))}, 
         NNDI: {len(pickle.dumps(NNDI))}&quot;&quot;&quot;))
  </code></pre>