__init__.py 文件源码

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

项目:heliopy 作者: heliopython 项目源码 文件源码
def normalize(vec):
    """
    Given an input vector normalize the vector

    Parameters
    ==========
    vec : array_like
        input vector to normalize

    Returns
    =======
    out : array_like
        normalized vector

    Examples
    ========
    >>> import spacepy.toolbox as tb
    >>> tb.normalize([1,2,3])
    [0.0, 0.5, 1.0]
    """
    # check to see if vec is numpy array, this is fastest
    if isinstance(vec, np.ndarray):
        out = (vec - vec.min())/np.ptp(vec)
    else:
        vecmin = np.min(vec)
        ptp = np.ptp(vec)
        out = [(val -  vecmin)/ptp for val in vec]
    return out
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号