I have a 3d grid with coordinates
x = linspace(0, Lx, Nx) y = linspace(0, Ly, Ny) z = linspace(0, Lz, Nz)
and I need to index the points (ie x [i], y [j], z [k]) within a certain radius R of the position (x0, y0, z0). N_i can be quite large. I can do a simple loop to find what I need
points=[] i0,j0,k0 = floor( (x0,y0,z0)/grid_spacing ) Nr = (i0,j0,k0)/grid_spacing + 2 for i in range(i0-Nr, i0+Nr): for j in range(j0-Nr, j0+Nr): for k in range(k0-Nr, k0+Nr): if norm(array([i,j,k])*grid_spacing - (x0,y0,k0)) < cutoff: points.append((i,j,k))
but it is rather slow. Is there a more natural / faster way to do this type of operation with numpy?
source share