It's pretty simple, even if you don't have all the points!
nrows = np.max(x) + 1
ncols = np.max(y) + 1
f_arr = np.zeros((nrows, ncols))
f_arr[x, y] = f
Points to remember:
- numpy indexing starts at zero
- "x" and "y" are loaded terms; numpy coordinates are more like those of a matrix, with (0, 0) at the top-left and the first coordinate going downwards (vertically), the second going rightwards (horizontally). I prefer therefore to use "r" and "c" as coordinates, to avoid confusion with standard Cartesian coordinates.
On Fri, Jul 17, 2015 at 3:24 PM, Gabriele Brambilla <[hidden email]> wrote:
I have 3 vectors containing x, y and f(x,y) values. They are ordered one with respect to the others but completely disordered in itself.
Let's say, for sake of simplicity, that f=x+y
x | y | f
1 | 2 | 3
5 | 1 | 6
And let's suppose that I know I have all the points to fill a grid.
I would like to obtain a mesh grid or a 2d python numpy array from it.
In c I know how to do it, but I know in python for cycles with element substitutions are avoidable...