histogram.py 文件源码

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

项目:Eskapade 作者: KaveIO 项目源码 文件源码
def get_bin_center(self, bin_label):
        """Return bin center for a given bin index

        :param bin_label: bin label for which to find the bin center
        :returns: bin center, can be float, int, timestamp
        """

        if not self.bin_specs:
            return None
        bin_idx = np.int64(bin_label)
        if 'bin_edges' in self.bin_specs:
            bin_edges = self.bin_specs['bin_edges']
            if bin_idx < 0 or bin_idx >= len(bin_edges):
                raise RuntimeError('bin_label "%s" does not fit in bin edges' % bin_label)
            # NOTE: computation below also works with timestamps! Order is
            # important.
            bin_width = bin_edges[bin_idx + 1] - bin_edges[bin_idx]
            bin_width_half = bin_width / 2.
            bin_center = bin_edges[bin_idx] + bin_width_half
        else:
            width = self.bin_specs['bin_width']
            offset = self.bin_specs.get('bin_offset', 0.)
            # NOTE: this notation also works with timestamps!
            bin_center = offset + (bin_idx + 0.5) * width
        return bin_center
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号