def task_divide(idx, n):
    """
    Split array into specified number of sub-arrays.

    Used in context of tasks.

    Parameters
    ----------
    idx
        List of tasks.
    n
        Number of sub-arrays to split.
    """
    total = len(idx)
    if n <= 0 or 0 == total:
        return [idx]
    if n > total:
        return [idx]
    elif n == total:
        return [[i] for i in idx]
    else:
        j = total // n
        tasks = []
        for i in range(0, (n - 1) * j, j):
            tasks.append(idx[i:i + j])
        tasks.append(idx[(n - 1) * j:])
        return tasks