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

Juan Nunez-Iglesias jni.soma at gmail.com
Fri Jul 17 15:49:11 EDT 2015


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 <
gb.gabrielebrambilla at gmail.com> 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
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20150717/42983d30/attachment.html>


More information about the SciPy-User mailing list