utils.py 文件源码

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

项目:pyGAM 作者: dswah 项目源码 文件源码
def round_to_n_decimal_places(array, n=3):
    """
    tool to keep round a float to n decimal places.

    n=3 by default

    Parameters
    ----------
    array : np.array
    n : int. number of decimal places to keep

    Returns
    -------
    array : rounded np.array
    """
    # check if in scientific notation
    if issubclass(array.__class__, float) and '%.e'%array == str(array):
        return array # do nothing

    shape = np.shape(array)
    out = ((np.atleast_1d(array) * 10**n).round().astype('int') / (10.**n))
    return out.reshape(shape)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号