state_enum.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:PyME 作者: vikramsunkara 项目源码 文件源码
def pack_distribution(self, p_sparse, p_dense=None):
        """
        convenience routine to translate a distribution from a dictionary to
        a dense array, using this state enumeration 
        """

        if p_dense is None:
            p_dense = numpy.zeros((self.size, ), dtype=numpy.float)

        # guard against case where p_sparse is empty
        if len(p_sparse) == 0:
            return p_dense

        p_states, p_values = domain.from_mapping(p_sparse)

        # now sort the states, keeping them synchronised with the
        # ordering of the values
        order = numpy.lexsort(p_states)
        p_states = p_states[:, order]
        p_values = p_values[order]
        p_indices = self.indices(p_states)
        p_dense[p_indices] = p_values
        return p_dense
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号