resize.py 文件源码

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

项目:pytorch_fnet 作者: AllenCellModeling 项目源码 文件源码
def resize(orig, factor, method="nearest"):
    """
    Scales a numpy array to a new size using a specified scaling method
    :param orig: n-dimen numpy array to resize
    :param factor: integer, double, or n-tuple to scale orig by
    :param method: string, interpolation method to use when resizing. Options are "nearest",
    "bilinear", and "cubic". Default is "nearest"
    :return: n-dimen numpy array
    """
    method_dict = {'nearest': 0, 'bilinear': 1, 'cubic': 2}
    if method.lower() not in method_dict:
        raise ValueError("Invalid interpolation method. Options are: " + ", ".join(method_dict.keys()))
    try:
        return zoom(orig, factor, order=method_dict[method.lower()])
    except RuntimeError:
        # raised by zoom when factor length does not match orig.shape length
        raise ValueError("Factor sequence length does not match input length")
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号