def _cart_to_sph(cart):
 assert ((cart.ndim == 2) and (cart.shape[1] == 3))
 cart = np.atleast_2d(cart)
 out = np.empty((len(cart), 3))
 out[:, 0] = np.sqrt(np.sum((cart * cart), axis=1))
 out[:, 1] = np.arctan2(cart[:, 1], cart[:, 0])
 out[:, 2] = np.arccos((cart[:, 2] / out[:, 0]))
 return out

def _cart_to_sph ( cart ) : assert ( ( cart . ndim == 2 ) and ( cart . shape [ 1 ] == 3 ) ) cart = np . atleast_2d ( cart ) out = np . empty ( ( len ( cart ) , 3 ) ) out [ : , 0 ] = np . sqrt ( np . sum ( ( cart * cart ) , axis = 1 ) ) out [ : , 1 ] = np . arctan2 ( cart [ : , 1 ] , cart [ : , 0 ] ) out [ : , 2 ] = np . arccos ( ( cart [ : , 2 ] / out [ : , 0 ] ) ) return out
convert cartesian coordinates to spherical coordinates .