import torch


def cart2polar(x, y):
    """
    Transform Cartesian coordinates to polar.
    Parameters
    ----------
    x, y : floats or arrays
        Cartesian coordinates
    Returns
    -------
    r, theta : floats or arrays
        Polar coordinates
    """
    r = torch.sqrt(x**2 + y**2)
    theta = torch.atan2(y,x)  # θ referenced to vertical
    return r, theta