def enumerate_subsets(nums, upper=5, set_upper=True):
    """

    Get all subsets of an array (the empty set [] is excluded).

    Parameters:
        nums: (list) an array that needs to get subsets from.
        upper: (int, optional) maximum length of the generated subset to be included.
            If set_upper = False, subsets with lengths from 1 to `upper` will be included in the final result set.
            Otherwise, only subsets with length = `upper` will be included.
        set_upper: (boolean, optional) whether to return subsets that have length = `upper`.

    Return:
        a list of arrays that are the subsets of `nums`.

    """

    def backtrack(first=0, curr=[]):
        if len(curr) == k and len(curr) > 0:
            output.append(curr[:])
        for i in range(first, len(nums)):
            curr.append(nums[i])
            backtrack(i + 1, curr)
            curr.pop()

    output = []
    for k in range(upper + 1):
        backtrack()

    if set_upper:
        return_list = [x for x in output if len(x) == upper]
        return return_list
    else:
        return output