[Numpy-discussion] Understanding mgrid

Robert Kern robert.kern@gmail....
Fri Sep 19 14:20:06 CDT 2008

On Fri, Sep 19, 2008 at 14:13, Brad Malone <brad.malone@gmail.com> wrote:
> Thanks for the response Robert.
> So, at least in this case, the results of mgrid (or indices) only provides
> information about the spacing of the grid and not on the absolute value of
> the point coordinates?

No, they give indices. You can use those indices in a variety of ways.
In my example, I used them to index into vectors which gave the
absolute positions of the grid lines. That turned into bricks giving
the absolute coordinates for each 3D grid point.

> In your example, is there a way to see within your x[ix], y[iy], and z[iz]
> matrices the same collection of points that you would see if you did
> something like the following?
> points=[]
> x=linspace(0,1,3)
> y=linspace(1,2.5,4)
> z=linspace(3,5,5)
> for k in z.tolist():
>     for j in y.tolist():
>          for i in x.tolist():
>                   point=array([i,j,k])
>                   points.append(point)

points = column_stack([x[ix].flat, y[iy].flat, z[iz].flat])

Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
 -- Umberto Eco

More information about the Numpy-discussion mailing list