import torch


def imag(z):
    """
    Returns the imaginary part of pytorch tensor.

    Parameters
    ----------
    z : tensor
        Input.

    Returns
    -------
    tensor
        Output.

    """
    if torch.is_complex(z):
        return z.imag
    else:
        return torch.zeros_like(z)