code: def cart2dir(cart):
      
      cart = np.array(cart)
      rad = old_div(np.pi, 180.)  # constant to convert degrees to radians
      if len(cart.shape) > 1:
          Xs, Ys, Zs = cart[:, 0], cart[:, 1], cart[:, 2]
      else:  # single vector
          Xs, Ys, Zs = cart[0], cart[1], cart[2]
      if np.iscomplexobj(Xs):
          Xs = Xs.real
      if np.iscomplexobj(Ys):
          Ys = Ys.real
      if np.iscomplexobj(Zs):
          Zs = Zs.real
      Rs = np.sqrt(Xs**2 + Ys**2 + Zs**2)  # calculate resultant vector length
      # calculate declination taking care of correct quadrants (arctan2) and
      # making modulo 360.
      Decs = (old_div(np.arctan2(Ys, Xs), rad)) % 360.
      try:
          # calculate inclination (converting to degrees) #
          Incs = old_div(np.arcsin(old_div(Zs, Rs)), rad)
      except:
          print('trouble in cart2dir')  # most likely division by zero somewhere
          return np.zeros(3)
  
      return np.array([Decs, Incs, Rs]).transpose()
docs: Converts a direction in cartesian coordinates into declination, inclinations
  
      Parameters
      ----------
      cart : input list of [x,y,z] or list of lists [[x1,y1,z1],[x2,y2,z2]...]
  
      Returns
      -------
      direction_array : returns an array of [declination, inclination, intensity]
  
      Examples
      --------
      >>> pmag.cart2dir([0,1,0])
      array([ 90.,   0.,   1.])