import math
import itertools


def permutate(k, l_exp):

    """
    Generate the permutations for all exponents of y
    :param k: number of meaningful directions
    :param l_exp: expansion order
    :return perms: array of permutations
    """

    Nt = int(math.factorial(l_exp + k) / (math.factorial(l_exp) * math.factorial(k)))

    lst = [ll for ll in range(l_exp + 1)] * k
    perms_all = set(itertools.permutations(lst, k))
    perms = []
    for per in perms_all:
        if sum(per) <= l_exp:
            perms.append(per)

    return perms