0

I´m trying to interpolate data from a 2D array in python using scipy.interpolate.interp2d. However, I don´t think I fully understand what it is doing ,so any help is appreciated. I am trying to do something similar to what is suggested here Link.

My code is below:

%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
from scipy import interpolate
from scipy.interpolate import griddata

p = np.array([[1,2,3,4,5,6,7,8,9,1],[1,2,3,4,5,6,7,8,9,1],  
              [1,6,3,4,8,6,7,8,9,1],[1,2,3,4,5,6,7,89,9,1],
              [1,56,3,4,5,6,7,67,6,1],[1,2,3,4,7,6,7,8,9,1],
              [1,2,3,5,5,6,7,6,9,1],[1,2,3,6,5,6,7,45,9,1],
              [9,2,3,4,21,6,7,8,9,1],[1,8,3,3,5,6,7,5,9,1]])
print(pf)
mymin, mymax = 0, 9
X = np.linspace(mymin,mymax,10)
Y = np.linspace(mymin,mymax,10)

Xnew = np.linspace(mymin,mymax,20)
Ynew = np.linspace(mymin,mymax,20)

f = interpolate.interp2d(x,y,p,kind='cubic')

Po = f(Xnew,Ynew)
print(Po)

When I run it, the following error message is displayed:

ValueError: Invalid length for input z for non rectangular grid

Tai
  • 7,684
  • 3
  • 29
  • 49
Diego RG
  • 1
  • 2
  • 1
    Your code runs for me with no errors (except I do have to correct your print(pf) to print(p) and the interp2d portion by replacing x and y with X and Y (I am assuming these are just typos on here...) – jfish003 Mar 30 '18 at 05:06
  • Could be a version problem. What are your scipy/numpy versions? ALso please post the full error message - we need to know where the error is happening. – MB-F Mar 30 '18 at 07:02

0 Answers0