[Numpy-discussion] numpy-izing a loop

Paul Rudin paul@rudin.co...
Thu Feb 12 02:55:57 CST 2009


Paul Rudin <paul@rudin.co.uk> writes:

> def compute_voxels2(depth_buffers):
>     dim = depth_buffers[0].shape[0]
>     znear, zfar, ynear, yfar, xnear, xfar = depth_buffers
>     z = numpy.arange(dim)
>     y = numpy.arange(dim)[:, None]
>     x = numpy.arange(dim)[:, None, None]
>
>     return  ((xnear[y,z] < xfar[y, z]) &
>              (ynear[x, z] < yfar[x, z]) &
>              (znear[x,y] < zfar[x,y]))
>

... or, more succinctly:

def compute_voxels2(znear, zfar, ynear, yfar, xnear, xfar):   
    return  ( (xnear<xfar) &
              (ynear < yfar)[:,None] &
              (znear < zfar)[:, :, None])

>
> All that remains is for me to verify that it's actually the result I want :)
>

Which it is, although getting the 6 planes passed in oriented correctly
in 3d-space makes my head hurt :/



More information about the Numpy-discussion mailing list