regressor.py 文件源码

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

项目:piecewise 作者: DataDog 项目源码 文件源码
def _preprocess(t, v):
    """ Raises and exception if any of the inputs are not valid.
    Otherwise, returns a list of Points, ordered by t.
    """
    # Validate the inputs.
    if len(t) != len(v):
        raise ValueError('`t` and `v` must have the same length.')
    t_arr, v_arr = np.array(t), np.array(v)
    if not np.all(np.isfinite(t)):
        raise ValueError('All values in `t` must be finite.')
    finite_mask = np.isfinite(v_arr)
    if np.sum(finite_mask) < 2:
        raise ValueError('`v` must have at least 2 finite values.')
    t_arr, v_arr = t_arr[finite_mask], v_arr[finite_mask]
    if len(np.unique(t_arr)) != len(t_arr):
        raise ValueError('All `t` values must be unique.')

    # Order both arrays by t-values.
    sort_order = np.argsort(t_arr)
    t_arr, v_arr = t_arr[sort_order], v_arr[sort_order]

    return t_arr, v_arr
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号