网格和标记3D点
我的矩阵为3D点。我想将它们量化为空间网格,并以其网格编号表示该矩阵。 假设矩阵是 d
D = np.array([[-45.08341177, 34.40457052, 7.63253164],
[-46.81391587, 34.35034554, 8.08080687],
[-48.25988676, 34.29036266, 8.11271667],
[-42.78217419, 24.51951629, 5.04130893],
[-44.50295096, 25.34408096, 5.26748238],
[-46.18559432, 25.60061165, 5.19218065]])
我将x,y和z放入数组中,
x = D[:,0]
y = D[:,1]
z = D[:,2]
现在我在上述代码上找到了空间网格的极限
r = np.zeros(x.shape)
n = 25
xE = np.linspace(np.min(x), np.max(x), num = n+1 )
yE = np.linspace(np.min(y), np.max(y), num = n+1 )
zE = np.linspace(np.min(z), np.max(z), num = n+1 )
,n显示了网格大小。在这种情况下,它是nxnxn,因为空间为3D。
现在我想标记每个点。这是在此链接。
如果任何专家可以帮助您,则只有下面给出的代码不会进入Python。
[MATLAB版本]
idx = 1;
for ii = 1:numel(xE)-1
for jj = 1:numel(yE)-1
for kk = 1:numel(zE)-1
r(x>xE(ii) & x<=xE(ii+1) & y>yE(jj) & y<=yE(jj+1) & z>zE(kk) & z<=zE(kk+1)) = idx;
idx = idx + 1;
end
end
end
I have matrix of 3D points. I want to quantize them into spatial grid and late represent that matrix by their grid number.
Let say the matrix is D
D = np.array([[-45.08341177, 34.40457052, 7.63253164],
[-46.81391587, 34.35034554, 8.08080687],
[-48.25988676, 34.29036266, 8.11271667],
[-42.78217419, 24.51951629, 5.04130893],
[-44.50295096, 25.34408096, 5.26748238],
[-46.18559432, 25.60061165, 5.19218065]])
I take x, y, and z into arrays
x = D[:,0]
y = D[:,1]
z = D[:,2]
Now I find the limit of spatial grid
r = np.zeros(x.shape)
n = 25
xE = np.linspace(np.min(x), np.max(x), num = n+1 )
yE = np.linspace(np.min(y), np.max(y), num = n+1 )
zE = np.linspace(np.min(z), np.max(z), num = n+1 )
on above code, n shows the grid size. In this case it is nxnxn as space is 3D.
Now I want to label each point. This is done in Matlab on this link.
Only the code given below part is not getting into Python, if any expert may kindly help.
[Matlab version]
idx = 1;
for ii = 1:numel(xE)-1
for jj = 1:numel(yE)-1
for kk = 1:numel(zE)-1
r(x>xE(ii) & x<=xE(ii+1) & y>yE(jj) & y<=yE(jj+1) & z>zE(kk) & z<=zE(kk+1)) = idx;
idx = idx + 1;
end
end
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可能有更聪明的方法可以做到这一点,但这将完成工作。看来您想跨过3D垃圾箱,并使用垃圾箱“数字”作为位于该垃圾箱中的任何点的标签。
您可以使用
np.histogramdd
获取每个轴的边缘。然后迭代每对边缘以创建一个3D垃圾箱,然后检查哪个点位于该垃圾箱内。您可以使用itertools.product
来浏览所有边的组合。您要求将其作为函数,但是在这种情况下,对象更合适。我们需要存储有关垃圾箱边缘的信息。
您会这样使用它:
There is probably more clever way to do this, but this will get the job done. It looks like you want to step through a 3D grid of bins and use the bin "number" as a label for any points that reside in that bin.
You can use
np.histogramdd
to get the edges for each axis. Then iterate through each pair of edges to create a 3D bin, and check which points fall within that bin. You can useitertools.product
to walk through all combinations of edges.You requested this as a function, but an object is more appropriate in this case. We need to store the information about the bin edges.
You would use it like this: