#NEWLINE# def cartesian_to_spherical( x , y , z ) : #NEWLINE# #INDENT# '\n    Convert cartesian coordinates to spherical coordinates.\n    \n    :param x: x\n    :param y: y\n    :param z: z\n    \n    .. math:: r = \\sqrt{\\left( x^2 + y^2 + z^2 \\right)}\n    .. math:: \\theta = \\arccos{\\frac{z}{r}}\n    .. math:: \\phi = \\arccos{\\frac{y}{x}}\n    ' #NEWLINE# x = np . asanyarray ( x ) #NEWLINE# y = np . asanyarray ( y ) #NEWLINE# z = np . asanyarray ( z ) #NEWLINE# r = np . linalg . norm ( np . vstack ( ( x , y , z ) ) , axis = 0 ) #NEWLINE# return ( r , np . arccos ( ( z / r ) ) , np . arctan ( ( y / x ) ) )