[SciPy-User] order data in a grid with numpy

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[SciPy-User] order data in a grid with numpy

Gabriele Brambilla
Hi,

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
they areĀ 
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...

Do you have any solution?

Thanks

Gabriele

_______________________________________________
SciPy-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/scipy-user
Reply | Threaded
Open this post in threaded view
|

Re: order data in a grid with numpy

Juan Nunez-Iglesias
Hi Gabriele,

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.

Juan.

On Fri, Jul 17, 2015 at 3:24 PM, Gabriele Brambilla <[hidden email]> wrote:
Hi,

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
they areĀ 
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...

Do you have any solution?

Thanks

Gabriele

_______________________________________________
SciPy-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/scipy-user



_______________________________________________
SciPy-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/scipy-user