小编leo*_*leo的帖子

Python:快速离散插值

给定一个表示离散坐标变换函数的 4D 数组,使得

arr[x_in, y_in, z_in] = [x_out, y_out, z_out]

我想插值arr到具有更多元素的网格(假设中的样本arr最初是从高元素立方体的规则间隔网格中提取的)。我已经尝试过RegularGridInterpolator来自 scipy,但是这相当慢:

import numpy as np
from scipy.interpolate import RegularGridInterpolator
from time import time

target_size   = 32
reduced_size  = 5

small_shape = (reduced_size,reduced_size,reduced_size,3)
cube_small  = np.random.randint(target_size, size=small_shape, dtype=np.uint8)

igrid = 3*[np.linspace(0, target_size-1, reduced_size)]
large_shape = (target_size, target_size, target_size,3)
cube_large  = np.empty(large_shape)

t0 = time()
interpol = RegularGridInterpolator(igrid, cube_small)
for x in np.arange(target_size):
    for y in np.arange(target_size):
        for z in np.arange(target_size):
            cube_large[x,y,z] = interpol([x,y,z])
print(time()-t0) …
Run Code Online (Sandbox Code Playgroud)

python interpolation numpy scipy

5
推荐指数
1
解决办法
77
查看次数

禁用特定模块的所有警告

我想禁用来自特定模块的所有警告,这样

import foo
import bar

foo.warning_method() # should not warn
bar.warning_method() # should warn
Run Code Online (Sandbox Code Playgroud)

有没有办法控制它,或者我是否需要为所有特定警告类型设置过滤器?

python warnings suppress-warnings

4
推荐指数
1
解决办法
2740
查看次数