title: Faster numpy cartesian to spherical coordinate conversion?
body: <p>I have an array of 3 million data points from a 3-axiz accellerometer (XYZ), and I want to add 3 columns to the array containing the equivalent spherical coordinates (r, theta, phi).  The following code works, but seems way too slow.  How can I do better?</p>
  
  <pre><code>import numpy as np
  import math as m
  
  def cart2sph(x,y,z):
      XsqPlusYsq = x**2 + y**2
      r = m.sqrt(XsqPlusYsq + z**2)               # r
      elev = m.atan2(z,m.sqrt(XsqPlusYsq))     # theta
      az = m.atan2(y,x)                           # phi
      return r, elev, az
  
  def cart2sphA(pts):
      return np.array([cart2sph(x,y,z) for x,y,z in pts])
  
  def appendSpherical(xyz):
      np.hstack((xyz, cart2sphA(xyz)))
  </code></pre>