title: python: calculate center of mass
body: <p>I have a data set with 4 columns: x,y,z, and value, let's say:</p>
  
  <pre><code>x  y  z  value
  0  0  0  0
  0  1  0  0
  0  2  0  0
  1  0  0  0
  1  1  0  1
  1  2  0  1
  2  0  0  0
  2  1  0  0
  2  2  0  0
  </code></pre>
  
  <p>I would like to calculate the center of mass <code>CM = (x_m,y_m,z_m)</code> of all values. In the present example, I would like to see <code>(1,1.5,0)</code> as output.</p>
  
  <p>I thought this must be a trivial problem, but I can't find a solution to it in the internet. <code>scipy.ndimage.measurements.center_of_mass</code> seems to be the right thing, but unfortunately, the function always returns two values (instead of 3). In addition, I can't find any documentation on how to set up an <code>ndimage</code> from an array: Would I use a numpy array N of shape <code>(9,4)</code>? Would then N[:,0] be the x-coordinate?</p>
  
  <p>Any help is highly appreciated.</p>