def get_w_or_h_matrix(nmf_results, k, w_or_h):
    """
    Get W or H matrix from nmf_results.
    :param nmf_results: dict;
    :param k: int;
    :param w_or_h: str; 'w', 'W', 'H', or 'h'
    :return: DataFrame; W or H matrix for this k
    """

    w_or_h = w_or_h.strip()
    if w_or_h.lower() not in ('w', 'h'):
        raise TypeError('w_or_h must be one of \'w\' or \'h\'.')

    return nmf_results[k][w_or_h.lower()]