def neighbors(img, row, col):
    """
    Parameters
    ==========
    img: 3-D numpy.array
        the image
    row: int
    col: int
        coordinates for the pixel to calculate energy for

    Returns
    =======
        tuple of 3 1-D numpy arrays [r,g,b]
           y0
        x0 -- x1
           y1
    """
    height, width = img.shape[:2]

    if row == 0:
        y0 = img[height-1][col]
        y1 = img[row+1][col]
    elif row == height - 1:
        y0 = img[row-1][col]
        y1 = img[0][col]
    else:
        y0 = img[row-1][col]
        y1 = img[row+1][col]

    if col == 0:
        x0 = img[row][width-1]
        x1 = img[row][col+1]
    elif col == width - 1:
        x0 = img[row][col-1]
        x1 = img[row][0]
    else:
        x0 = img[row][col-1]
        x1 = img[row][col+1]

    return x0, x1, y0, y1