math.py 文件源码

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

项目:pymake 作者: dtrckd 项目源码 文件源码
def degree_hist(_degree, filter_zeros=False):
    degree = list(_degree.values()) if type(_degree) is dict else _degree

    max_c = np.max(degree)
    d = np.arange(max_c+1)
    dc = np.bincount(degree, minlength=max_c+1)

    if len(d) == 0:
        return [], []

    if dc[0] > 0:
        lgg.debug('%d unconnected vertex' % dc[0])
    d = d[1:]
    dc = dc[1:]


    if filter_zeros is True:
        #d, dc = zip(*filter(lambda x:x[1] != 0, zip(d, dc)))
        nzv = (dc != 0)
        d = d[nzv]
        dc = dc[nzv]

    return d, dc
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号