Python scipy 模块,isnan() 实例源码

我们从Python开源项目中,提取了以下3个代码示例,用于说明如何使用scipy.isnan()

项目:house-price-map    作者:andyljones    | 项目源码 | 文件源码
def with_walking(time_arr, mins_per_square=1.3, transfer_constant=5):
    arr = time_arr.copy()
    cross_footprint = sp.array([[0, 1, 0], [1, 1, 1], [0, 1, 0]]).astype(bool)
    diag_footprint = sp.array([[1, 0, 1],[0, 1, 0], [1, 0, 1]]).astype(bool)
    arr[sp.isnan(arr)] = sp.inf
    for i in range(60):
        cross_arr = sp.ndimage.minimum_filter(arr, footprint=cross_footprint)
        cross_arr[sp.isnan(cross_arr)] = sp.inf
        cross_changes = (cross_arr != arr)
        cross_arr[cross_changes] += 1*mins_per_square

        diag_arr = sp.ndimage.minimum_filter(arr, footprint=diag_footprint)
        diag_arr[sp.isnan(diag_arr)] = sp.inf
        diag_changes = (diag_arr != arr)
        diag_arr[diag_changes] += 1.4*mins_per_square

        arr = sp.minimum(cross_arr, diag_arr)

    arr[sp.isinf(arr)] = sp.nan

    return arr + transfer_constant
项目:house-price-map    作者:andyljones    | 项目源码 | 文件源码
def smooth(arr, sigma=5):
    filled = arr.copy()
    nans = sp.isnan(arr)    

    filled[nans] = 0
    smoothed = sp.ndimage.gaussian_filter(filled, sigma=sigma, truncate=10)  
    missing_coefs = sp.ndimage.gaussian_filter((~nans).astype(float), sigma=sigma, truncate=10)

    corrected = smoothed/missing_coefs

    return corrected
项目:house-price-map    作者:andyljones    | 项目源码 | 文件源码
def get_relative_prices(walking_time, smoothed_prices):
    x = walking_time.flatten()
    y = smoothed_prices.flatten()
    mask = sp.isnan(x) | sp.isnan(y)

    spline = sp.interpolate.UnivariateSpline(x[~mask], y[~mask], s=len(x))
    v = spline(x)

    rel = (y - v).reshape(walking_time.shape)

    return rel