import torch


def as_complex(x):
    """
    In pytorch, a complex array is represented as a real array with an extra length-2 axis at the end.
    This function takes a real-valued array x and adds complex axis where the real part is set to x and the imaginary part is set to 0.
    """
    imaginary = torch.zeros_like(x)
    z = torch.stack((x, imaginary), dim=x.ndimension())
    return z