howto store 2D function values and their grid points
Dear all, I can't wrap my head around this. Mathematically it's not hard, I just don't know how to store and access it without many loops. I have a function f(x,y). I would like to calculate it at x = arange(20,101,20) and y = arange(2,30,2) How do I store that in a multi-dimensional array and preserve the grid points where I did the calculation so that I could plot later groups of function plots like this: for elem in y-values plot(x_values, f(x,y=elem) or for elem in x-values: plot(y_values, f(x=elem,y) I can smell that the solution can not be so hard, but I currently understand how to keep the points where I did the evaluation of the function. Maybe it is also imaginable to do something with functional tricks as 'map'? Thanks for any suggestions! Best regards, Michael
On 12/6/2011 9:54 AM, K.-Michael Aye wrote:
I have a function f(x,y).
I would like to calculate it at x = arange(20,101,20) and y = arange(2,30,2)
How do I store that in a multi-dimensional array and preserve the grid points where I did the calculation
In [5]: X, Y = np.meshgrid(range(3), range(4)) In [6]: X Out[6]: array([[0, 1, 2], [0, 1, 2], [0, 1, 2], [0, 1, 2]]) In [7]: Y Out[7]: array([[0, 0, 0], [1, 1, 1], [2, 2, 2], [3, 3, 3]]) now do your f(X, Y) -Chris -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker@noaa.gov
participants (2)
-
Chris Barker -
K.-Michael Aye