- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有一个 csv 文件,其中包含随机位置的纬度、经度和海拔值。我想应用 IDW 插值来生成规则网格。我使用 scipy.spatial.cKDTree 进行最近邻搜索并查找未知点的高程值。当输出网格具有尺寸 (z < 1000 X1000) 时,以下代码可以正常工作。如果维度增加,代码运行速度会非常慢。请帮助我矢量化 for 循环,而不使用 cKDTree 进行删除。谢谢。
## Inverse distance weighted function
def idw(p, dist, values):
dist_pow = np.power(dist, 2)
nominator = np.sum(values/dist_pow)
denominator = np.sum(1/dist_pow)
if denominator > 0:
return nominator/denominator
else:
return none
## Reading the lat/lon and elevation values from file
lat = []
lon = []
ele = []
with open('VSKP_ground_dat.csv') as read:
csvreader = csv.DictReader(read)
for row in csvreader:
lat.append(float(row['LAT']))
lon.append(float(row['LON']))
ele.append(float(row['ALT']))
xycoord = np.c_[lon,lat]
ele_arr = np.array(ele)
## ------------- Creating KDTree
point_tree = spatial.cKDTree(xycoord, leafsize=25)
## ------------- Creating empty grid matrix with np.zeros
xmin, xmax, ymin, ymax = 81.903158, 83.352158, 17.25856, 18.40056
## --------- Defining resolution
xres, yres = 0.01, 0.01
x = np.arange(xmin, xmax, xres)
y = np.arange(ymin, ymax, yres)
z = np.zeros((x.shape[0], y.shape[0]), dtype=np.float16)
for i, val1 in enumerate(x):
for j, val2 in enumerate(y):
p = np.array([val1, val2])
# points_idx = point_tree.query_ball_point(p, dist_2)
distances, points_idx = point_tree.query(p, k=6, eps=0)
ele_vals = ele_arr[points_idx]
value = idw(p, distances, ele_vals)
z[i,j] = value
最佳答案
首先,修复您的 idw
函数以处理最后一个索引:
def idw(dist, values, p = 2):
out = np.empty(dist.shape[:-1])
mask = np.isclose(dist, 0).any(-1)
out[mask] = values[np.isclose(dist, 0)] # should be only one per point
dist_pow = np.power(dist[~mask], -p) # division is costly, do it once
nominator = np.sum(values[~mask] * dist_pow, axis = -1) # over mask to prevent divide by zero
denominator = np.sum(dist_pow, index = -1)
out[~mask] = nominator / denominator
return out
然后根据np.meshgrid
输出完成剩下的工作
x = np.arange(xmin, xmax, xres) # len i
y = np.arange(ymin, ymax, yres) # len j
xy = np.stack(np.meshgrid(x, y), axis = -1) # shape(i, j, 2)
distances, points_idx = point_tree.query(xy, k=6, eps=0) # shape (i, j, 6)
ele_vals = ele_arr[points_idx] # shape (i, j, 6)
z = idw(distances, ele_vals) # shape (i, j)
关于python - 用于在两个数组上搜索 ckdtree 的向量化循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47747142/
我想使用Tensorflow的transform_graph工具优化图形。我尝试优化 MultiNet 中的图表(以及其他具有类似编码器-解码器架构的)。然而,优化后的图在使用 quantize_we
我试图在 C# 中将图像量化为 10 种颜色,但在绘制量化图像时遇到问题,我已经制作了映射表并且它是正确的,我已经制作了原始图像的副本并且正在更改基于映射表的像素颜色,我使用下面的代码: bm = n
我需要降低UIImage的颜色深度,但是我不知道该怎么做。结果应与在Photoshop中应用索引颜色相同。 我的目标是要具有较低的色深(32色或更低)。也许这是我的错,但我没有找到解决方法。令人惊讶的
我有大量的 numpy 向量,每个形状 (3,) 都有 8 位整数值: vec = np.random.randint(2**8, size=3) 我想通过一些已知的缩减因子将这些向量量化到更小的空间
我正在用 jQuery 编写一个心理学应用程序。我的项目的一部分需要测量用户对声音的 react 时间(用户按下一个键)。因此,我需要在调用(&时间戳)声音文件和实际开始播放之间的延迟尽可能小地播放声
最近,我开始使用 Tensorflow + Keras 创建神经网络,我想尝试 Tensorflow 中提供的量化功能。到目前为止,使用 TF 教程中的示例进行试验效果很好,我有这个基本的工作示例(来
使用当前的 Tensorflow quantization ops ,我将如何在推理过程中模拟每 channel 量化?这paper将每层量化定义为 We can specify a single q
我已经卡住了我的模型并获得了 .pb 文件。然后我在 Linux 上使用 tocoConverter 量化我的模型,因为 Windows 不支持它。我有 quantized_model.tflite。
我将 git 用于一个稍微不寻常的目的——它在我写小说时存储我的文本。 (我知道,我知道......令人讨厌。) 我正在尝试跟踪生产力,并想衡量后续提交之间的差异程度。作家代表“作品”的是“文字”,至
quantization有什么区别和 simplification ? 量化是另一种简化方式吗? 在某些情况下使用量化更好吗? 或者我应该同时使用两者? 最佳答案 几何体的总大小由两个因素控制:点数和
扎克伯格说,Llama3-8B还是太大了,不适合放到手机中,有什么办法? 量化、剪枝、蒸馏,如果你经常关注大语言模型,一定会看到这几个词,单看这几个字,我们很难理解它们都干了些什么,但
相对于
我正在将一些我无法控制的 XML 转换为 XHTML。 XML 模式定义了一个 段落标记和 和 用于列表。 我经常在这个 XML 中找到嵌套在段落中的列表。因此,直接转换会导致 s 嵌套在 中s,
我看到过这样的说法:CNN 的更深层次可以学习识别更复杂的特征。这通常附带一张早期过滤器识别直线/简单曲线的图片,以及后期过滤器识别更复杂图案的图片。它具有直观意义:您距离数据越远,您对数据的理解就越
在使用 C++ 的带有 tensorflow lite 的树莓派上,对象检测无法正常工作。我的代码编译并运行,但输出似乎从未得到正确填充。我是否会遗漏任何依赖项或错误地访问结果? 我遵循了以下教程:
如何衡量/量化 Corona SDK 游戏应用中的“迟缓”? 我在我构建的基于 Corona SDK 的物理游戏(使用 Box2D)上寻找旧手机(例如 iPhone 4、Samsung GT-I900
我正在尝试创建一个 Tensorflow 量化模型,以便使用 Coral USB 加速器进行推理。这是我的问题的一个最小的独立示例: import sys import tensorflow as t
我有一个分位数回归模型,其中包含 1 个回归变量和 1 个回归变量。我想假设检验回归量在每个分位数上都相等。我想到的一种方法是在 {0.01,0.02,....,0.99} 上测试所有 tau。但是,
要求做,在 PGM 文件上使用 KMeans 进行 vector 量化(或图像压缩) 图像是 PMG 文件,其中 b = block 大小,k = 次数,t = 迭代,-g = 初始质心 图像是这样的
我是一名优秀的程序员,十分优秀!