def marginal_word_distrib(topic_word_distrib, p_t):
    """
    Return the marginal word distribution ``p(w)`` (term proportions derived from topic model) given the
    topic-word distribution (phi) `topic_word_distrib` and the marginal topic distribution ``p(T)`` `p_t`.
    The latter can be calculated with :func:`~tmtoolkit.topicmod.model_stats.marginal_topic_distrib`.

    :param topic_word_distrib: topic-word distribution; shape KxM, where K is number of topics, M is vocabulary size
    :param p_t: marginal topic distribution; array of size K
    :return: array of size M (vocabulary size) with marginal word distribution
    """
    return (topic_word_distrib.T * p_t).sum(axis=1)