import torch


def power_harmonics(z, k):
    """
    Compute the power harmonics of the input tensor.

    Parameters
    ----------
    z : tensor
        Input.
    k : tensor
        Exponents.

    Returns
    -------
    result : tensor
        Output.

    """
    indices_k_0 = torch.where(k == 0)[0]
    indices_other_k = torch.where(k >= 1)[0]
    
    result = z.clone()
    del z
    
    # k == 0
    result[..., indices_k_0, :, :] = torch.abs(torch.index_select(result, -3, indices_k_0)).to(result.dtype)

    # k >= 1
    other_k = k[indices_other_k].unsqueeze(-1).unsqueeze(-1)
    result[..., indices_other_k, :, :] = (torch.index_select(result, -3, indices_other_k)) ** other_k
    
    return result