code: def polar_to_cart(arr_p):
      
      if arr_p.shape[-1] == 1:
          arr_c = arr_p.copy()
      elif arr_p.shape[-1] == 2:
          arr_c = np.empty_like(arr_p)
          arr_c[..., 0] = arr_p[..., 0] * np.cos(arr_p[..., 1])
          arr_c[..., 1] = arr_p[..., 0] * np.sin(arr_p[..., 1])
      elif arr_p.shape[-1] == 3:
          arr_c = np.empty_like(arr_p)
          arr_c[..., 0] = arr_p[..., 0] * np.sin(
              arr_p[..., 1]) * np.cos(arr_p[..., 2])
          arr_c[..., 1] = arr_p[..., 0] * np.sin(
              arr_p[..., 1]) * np.sin(arr_p[..., 2])
          arr_c[..., 2] = arr_p[..., 0] * np.cos(arr_p[..., 1])
      else:
          raise Exception('Invalid vector for polar representation')
      return arr_c
docs: Return polar vectors in their cartesian representation.
  
      Parameters
      ----------
      arr_p: array, shape (a1, a2, ..., d)
          Polar vectors, with last axis indexing the dimension,
          using (radius, inclination, azimuth) convention.
  
      Returns
      -------
      arr_c: array, shape of arr_p
          Cartesian vectors.