title: How to calculate an angle between 2D vector and OX with numpy?
body: <p>Supposing, I have a 2D numpy array link this:</p>
  
  <pre><code>import numpy as np
  v = np.array([1, 2])
  </code></pre>
  
  <p>I want to consider it as a vector at a 2D flat, that has axis OX and OY. I am curious, is there a build-in or quite elegant way to calculate the angle between the vector and the axis OX? The angle should be from -PI to PI.</p>
  
  <p>I know, I could calculate with the help of <code>numpy.arctan</code> this way:</p>
  
  <pre><code>def calc_phi(v):
      if v[0] &gt; 0:
          return np.arctan(v[1] / v[0])
      else:
          if v[1] &gt; 0:
              if v[0] &lt; 0:
                  return np.pi + np.arctan(v[1] / v[0])
              else:
                  return np.pi
          elif v[1] &lt; 0:
              if v[0] &lt; 0:
                  return -np.pi + np.arctan(v[1] / v[0])
              else:
                  return -np.pi
          else:
              return 0.0
  </code></pre>
  
  <p>But it doesn't seem to be elegant, because I have to separately consider the cases x = 0, and x &lt; 0. So I think, <code>numpy</code> probably has a special function to calculate it.</p>