def array2dict( header, data ):
    """
    Reads (key, index) pairs from the header of the extension and uses them
    to assign each row of the data array to a dictionary.
    
    Parameters
    ----------
    header : astropy.io.fits.header.Header
        Header with the keys to the data array
    data : numpy.ndarray
        Data array

    Returns
    -------
    list of header dictionaries
    """
    
    # some headers are not keys but real headers: remove them
    keys_to_remove=['XTENSION', 'BITPIX', 'NAXIS', 'NAXIS1', 'NAXIS2', 'PCOUNT', 'GCOUNT']
    header_keys = dict( header )
    header_keys = {k: v for k, v in header_keys.items() if k not in keys_to_remove}

    # initialize dictionary list
    res = [dict() for x in range( data.shape[0] )]

    # fill dictionaries
    for i in range(0, data.shape[0]):
        res[i] = dict( zip( header_keys.keys(), data[i,list(header_keys.values())] ) )

    return res