title: Binning 2D data into overlapping circles in x,y
body: <p>I'm currently working with a fairly large dataset of 3D points (x,y,z) and would like an efficient means to identify which points are inside a set of circles in the xy plane, with radius r and centre (x1,y1), where x1 and y1 are grid coordinates (of length 120 each). The circles will overlap, and some points will belong to multiple circles.</p>
  
  <p>So the output would be the identities of 14400 circles (120*120), and which points in the (x,y,z) list are in each one.</p>
  
  <pre><code>import numpy as np
  
  def inside_circle(x, y, x0, y0, r):
      return (x - x0)*(x - x0) + (y - y0)*(y - y0) &lt; r*r
  
  x = np.random.random_sample((10000,))
  y = np.random.random_sample((10000,))
  
  x0 = np.linspace(min(x),max(x),120)
  y0 = np.linspace(min(y),max(y),120)
  
  idx = np.zeros((14400,10000))
  r = 2
  count = 0
  
  for i in range(0,120):
      for j in range(0,120):
          idx[count,:] = inside_circle(x,y,x0[i],y0[j],r)
          count = count + 1
  </code></pre>
  
  <p>where inside_circle is a function that gives an array of boolean True or False for each tested point x,y,z in circle of radius r, with centre x0[i] and x0[j]</p>
  
  <p>My main question is whether there is a more efficient way to do this than a nested for loop? Or even more efficient means to do anything here in general - as i'm quite new to python.</p>
  
  <p>Thanks for any responses!</p>
  
  <p>Alec.</p>