title: Creating a spherical mask from numpy array and getting array indices inside the sphere
body: <p>Hi I have a sample data for x, y, z positions:</p>
  
  <pre><code># x y z
  -0.120932 -0.300053 -0.296206
  -0.0978073 -0.304533 -0.291415
  -0.097738 -0.299779 -0.28466
  -0.118981 -0.293157 -0.292577
  -0.105695 -0.263689 -0.303431
  -0.0759291 -0.254051 -0.294597
  -0.0637251 -0.293032 -0.306507
  -0.083585 -0.290494 -0.311816
  -0.0928098 -0.294645 -0.294957
  </code></pre>
  
  <p>I would like to create a sphere of 5 units and then apply the spherical mask to get position coordinates only within that sphere. I would also like to get the indices of the corresponding rows (coordinates) that fall within the sphere.</p>
  
  <p>My code looks the following:</p>
  
  <pre><code>pos = 'data.txt'
  
  x, y, z = np.loadtxt(pos, unpack =True)
  
  
  h = len(x)
  w = len(y)
  l = len(z)
  center = [-0.120932, -0.300053, -0.296206]
  radius = 5.
  
  
  # create circular mask 
  def createCircularMask(h, w, l, center, radius):
  
      X, Y, Z = np.ogrid[:h, :w, :l]
          dist_from_center = np.sqrt((X - center[0])**2 + (Y-center[1])**2 + (Z-center[2]**2))
  
          mask = dist_from_center &lt;= radius
          return mask
  
  inside_x = x[createCircularMask]
  
  print inside_x
  print len(inside_x)
  </code></pre>
  
  <p>I am getting the folllowing error :</p>
  
  <pre><code>   File "density_map_test.py", line 41, in &lt;module&gt;
      inside_x = x[createCircularMask]
  IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices
  </code></pre>
  
  <p>Could you please clarify why I am getting this? and also How I get the indices too. Thanks in advance</p>