[Numpy-discussion] howto store 2D function values and their grid points

Chris Barker Chris.Barker at noaa.gov
Tue Dec 6 13:02:39 EST 2011


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 at noaa.gov



More information about the NumPy-Discussion mailing list