core.py 文件源码

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

项目:soif 作者: ceyzeriat 项目源码 文件源码
def round_fig(x, n=1, retint=False):
    """
    Rounds x at the n-th figure. n must be >1
    ex: 1234.567 with n=3-> 1230.0
    """
    if np.iterable(x):
        x = np.asarray(x).copy()
        ff = (x != 0)
        dd = 10**(np.floor(np.log10(np.abs(x[ff])))-n+1)
        x[ff] = np.round(x[ff]/dd)
        if not retint:
            x[ff] *= dd
        return x
    elif x != 0:
        dd = 10**(np.floor(np.log10(np.abs(x)))-n+1)
        x = np.round(x/dd)
        if not retint:
            x *= dd
        return x
    else:
        return x
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号