Integrating 2D data over an irregular grid in python
问题 So I have 2D function which is sampled irregularly over a domain, and I want to calculate the volume underneath the surface. The data is organised in terms of [x,y,z] , taking a simple example: def f(x,y): return np.cos(10*x*y) * np.exp(-x**2 - y**2) datrange1 = np.linspace(-5,5,1000) datrange2 = np.linspace(-0.5,0.5,1000) ar = [] for x in datrange1: for y in datrange2: ar += [[x,y, f(x,y)]] for x in xrange2: for y in yrange2: ar += [[x,y, f(x,y)]] val_arr1 = np.array(ar) data = np.unique(val