def ngram_slices(i, n, l):
    """
    Given index i, n-gram width n and array length l, returns slices
    for all n-grams containing an ith element
    """
    out = []

    a = i - n + 1
    if a < 0:
        a = 0

    b = i + 1
    if b + n > l:
        b = l - n + 1

    d = b - a

    for k in range(d):
        start = a + k
        stop = start + n
        out.append(slice(start, stop))

    return out