{"action":"created","issue":{"url":"https://api.github.com/repos/scipy/scipy/issues/4730","labels_url":"https://api.github.com/repos/scipy/scipy/issues/4730/labels{/name}","comments_url":"https://api.github.com/repos/scipy/scipy/issues/4730/comments","events_url":"https://api.github.com/repos/scipy/scipy/issues/4730/events","html_url":"https://github.com/scipy/scipy/issues/4730","id":68218573,"number":4730,"title":"scipy.interpolate.interp2d has unexpected behavior with Nan values","user":{"login":"mhearne-usgs","id":303058,"avatar_url":"https://avatars.githubusercontent.com/u/303058?v=3","gravatar_id":"","url":"https://api.github.com/users/mhearne-usgs","html_url":"https://github.com/mhearne-usgs","followers_url":"https://api.github.com/users/mhearne-usgs/followers","following_url":"https://api.github.com/users/mhearne-usgs/following{/other_user}","gists_url":"https://api.github.com/users/mhearne-usgs/gists{/gist_id}","starred_url":"https://api.github.com/users/mhearne-usgs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mhearne-usgs/subscriptions","organizations_url":"https://api.github.com/users/mhearne-usgs/orgs","repos_url":"https://api.github.com/users/mhearne-usgs/repos","events_url":"https://api.github.com/users/mhearne-usgs/events{/privacy}","received_events_url":"https://api.github.com/users/mhearne-usgs/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-04-13T23:32:47Z","updated_at":"2015-04-14T00:07:54Z","closed_at":null,"body":"I'm seeing what I would consider to be unexpected behavior from the scipy interpolate.interp2d function when there are NaN values in the input array.  The code snippet below should demonstrate the problem I'm seeing, namely that the interpolated grid has NaN values in all the rows above my little corner of NaN values in the input grid.  Questions:\r\n\r\n1) Is this the intended behavior?  If so, why?\r\n2) How can I achieve the results that would be more consistent between rows and columns?\r\n\r\nimport numpy as np\r\nfrom scipy import interpolate\r\n\r\nnrows = 4\r\nncols = 4\r\nz = np.arange(0,nrows*ncols,dtype=np.float).reshape((nrows,ncols))\r\nz[-2][0] = np.nan\r\nz[-1][0] = np.nan\r\nz[-2][1] = np.nan\r\nz[-1][1] = np.nan\r\nprint z\r\nprint\r\nx = np.arange(0,ncols)\r\ny = np.arange(0,nrows)\r\nxi = np.arange(0.5,ncols-1,1.0)\r\nyi = np.arange(0.5,nrows-1,1.0)\r\nf = interpolate.interp2d(x,y,z,kind='linear')\r\nzi = f(xi,yi) #interpolate at the points in between values\r\nprint zi \r\n\r\nThis returns:\r\n\r\n[[  0.   1.   2.   3.]\r\n [  4.   5.   6.   7.]\r\n [ nan  nan  10.  11.]\r\n [ nan  nan  14.  15.]]\r\n\r\n[[  nan   nan   4.5]\r\n [  nan   nan   8.5]\r\n [  nan   nan  12.5]]\r\n\r\nWhy don't I get:\r\n[[  2.5   3.5   4.5]\r\n [  nan   nan   8.5]\r\n [  nan   nan  12.5]]\r\n"},"comment":{"url":"https://api.github.com/repos/scipy/scipy/issues/comments/92542701","html_url":"https://github.com/scipy/scipy/issues/4730#issuecomment-92542701","issue_url":"https://api.github.com/repos/scipy/scipy/issues/4730","id":92542701,"user":{"login":"mhearne-usgs","id":303058,"avatar_url":"https://avatars.githubusercontent.com/u/303058?v=3","gravatar_id":"","url":"https://api.github.com/users/mhearne-usgs","html_url":"https://github.com/mhearne-usgs","followers_url":"https://api.github.com/users/mhearne-usgs/followers","following_url":"https://api.github.com/users/mhearne-usgs/following{/other_user}","gists_url":"https://api.github.com/users/mhearne-usgs/gists{/gist_id}","starred_url":"https://api.github.com/users/mhearne-usgs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mhearne-usgs/subscriptions","organizations_url":"https://api.github.com/users/mhearne-usgs/orgs","repos_url":"https://api.github.com/users/mhearne-usgs/repos","events_url":"https://api.github.com/users/mhearne-usgs/events{/privacy}","received_events_url":"https://api.github.com/users/mhearne-usgs/received_events","type":"User","site_admin":false},"created_at":"2015-04-14T00:07:54Z","updated_at":"2015-04-14T00:07:54Z","body":"Ok, this gets even weirder.  Depending on which corner you fill in with NaN values, you get very different results.  Here are the three other options:\r\n\r\n########### Option 2: NaN's in upper right corner############\r\nnrows = 4\r\nncols = 4\r\nz = np.arange(0,nrows*ncols,dtype=np.float).reshape((nrows,ncols))\r\nz[0][-2] = np.nan\r\nz[0][-1] = np.nan\r\nz[1][-2] = np.nan\r\nz[1][-1] = np.nan\r\nprint z\r\nprint\r\nx = np.arange(0,ncols)\r\ny = np.arange(0,nrows)\r\nxi = np.arange(0.5,ncols-1,1.0)\r\nyi = np.arange(0.5,nrows-1,1.0)\r\nf = interpolate.interp2d(x,y,z,kind='linear')\r\nzi = f(xi,yi) #interpolate at the points in between values\r\nprint zi\r\n####################################################\r\n\r\n########### Option 3: NaN's in upper left corner############\r\nnrows = 4\r\nncols = 4\r\nz = np.arange(0,nrows*ncols,dtype=np.float).reshape((nrows,ncols))\r\nz[0][0] = np.nan\r\nz[0][1] = np.nan\r\nz[1][0] = np.nan\r\nz[1][1] = np.nan\r\nprint z\r\nprint\r\nx = np.arange(0,ncols)\r\ny = np.arange(0,nrows)\r\nxi = np.arange(0.5,ncols-1,1.0)\r\nyi = np.arange(0.5,nrows-1,1.0)\r\nf = interpolate.interp2d(x,y,z,kind='linear')\r\nzi = f(xi,yi) #interpolate at the points in between values\r\nprint zi\r\n####################################################\r\n\r\n########### Option 3: NaN's in lower right corner############\r\nnrows = 4\r\nncols = 4\r\nz = np.arange(0,nrows*ncols,dtype=np.float).reshape((nrows,ncols))\r\nz[-2][-2] = np.nan\r\nz[-2][-1] = np.nan\r\nz[-1][-2] = np.nan\r\nz[-1][-1] = np.nan\r\nprint z\r\nprint\r\nx = np.arange(0,ncols)\r\ny = np.arange(0,nrows)\r\nxi = np.arange(0.5,ncols-1,1.0)\r\nyi = np.arange(0.5,nrows-1,1.0)\r\nf = interpolate.interp2d(x,y,z,kind='linear')\r\nzi = f(xi,yi) #interpolate at the points in between values\r\nprint zi\r\n####################################################"}}