misc.py 文件源码

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

项目:tensorflow-layer-library 作者: bioinf-jku 项目源码 文件源码
def custom_tensorflow_histogram(values, bins=100):
    import numpy as np
    import tensorflow as tf

    # Create histogram using numpy
    counts, bin_edges = np.histogram(values, bins=bins)

    # Fill fields of histogram proto
    hist = tf.HistogramProto()
    if len(values):
        hist.min = float(np.min(values))
        hist.max = float(np.max(values))
        hist.num = int(np.prod(values.shape))
        hist.sum = float(np.sum(values))
        hist.sum_squares = float(np.sum(values ** 2))
    else:
        hist.min = 0
        hist.max = 0
        hist.num = 0
        hist.sum = 0
        hist.sum_squares = 0
    bin_edges = bin_edges[1:]

    # Add bin edges and counts
    for edge in bin_edges:
        hist.bucket_limit.append(edge)
    for c in counts:
        hist.bucket.append(int(c))

    return hist
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号