def ndvi(red, nir):
    """
    Computes the normalized difference vegetation index for a
    Landsat scene.

    :param red: numpy.array, red band of a landsat scene
    :param nir: numpy.array, nir band of a landsat scene
    :return: ndvi as numpy.array
    """
    if red.shape != nir.shape:
        raise AttributeError('No equal shape')

    # vegetation index components
    x = nir - red
    y = nir + red

    # avoid division by zero error
    y[y == 0.0] = 1.0

    # NDVI (NIR - RED) / (NIR + RED)
    img = x / y

    img[y == 1.0] = 0.0

    # clip range to normal difference
    img[img < -1.0] = -1.0
    img[img > 1.0] = 1.0

    return img