简体   繁体   English

将x,y,z坐标排序到定义的体积Python / numpy中的数组中

[英]Sorting x,y,z coordinates into arrays within a defined volume Python/numpy

Hi I am fairly new and I hope you can answer my question or help me find a better method! 嗨,我相当新,我希望你能回答我的问题,或者帮我找到更好的方法!

Say I have a set of x,y,z coordinates that I want to subdivide into arrays containing the points within a certain volume (dV) of the total volume of the x,y,z space. 假设我有一组x,y,z坐标,我想细分为包含x,y,z空间总体积的特定体积(dV)内的点的数组。

I have been trying to sort each x,y,z coordinate by the x value first, then subdividing by some dx into a new dimension of the array, then within each of these subdivided dimensions, sorting the y values and redividing by dy, and then the same along the z axis, giving the sorted and subdivided coordinates 我一直试图先用x值对每个x,y,z坐标进行排序,然后将一些dx细分为数组的新维度,然后在每个细分维度内,对y值进行排序,并用dy重新划分,然后沿z轴相同,给出排序和细分的坐标

I have attempted to create an array to append the coordinate sets to... 我试图创建一个数组来附加坐标集...

  def splitter(array1):
    xSortx = np.zeros([10,1,3])
    for j in range(0,10):
        for i in range(len(array1)) :
            if (j * dx) <= array1[i][0] < (j + 1)*dx:
                np.append(xSortx[j],array1[i]) 

everything seemed to be working but the append part, i have heard append in python can be troubling so another method I tried was to create the multidimensional matrix first in order to fill it, but I ran into the problem that I do not know how to create a multidimensional matrix that could have for example 1 entry in the second dimension but 5 in the next index of the second ex: [[[0,0,0]],[[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0]]]. 一切似乎都工作,但附加部分,我听说追加python可能是麻烦所以我尝试的另一种方法是先创建多维矩阵,以填补它,但我遇到了我不知道怎么样的问题创建一个多维矩阵,可以在第二维中有1个条目,但在第二个ex的下一个索引中有5个:[[[0,0,0]],[[0,0,0],[0,0 ,0],[0,0,0],[0,0,0],[0,0,0]]]。

I would really appreciate any tips or advice, let me know if this is not very clear and I will try to explain it more! 我真的很感激任何提示或建议,如果不是很清楚,请告诉我,我会尝试更多解释!

I believe this is what you want: 我相信这就是你想要的:

# define your working volume
Vmin = np.array([1,2,3])
Vmax = np.array([4,5,6])
DV = Vmax-Vmin

# define your subdividing unit
d = 0.5
N = np.ceil(DV / d).astype(int) # number of bins in each dimension

def splitter(array):
    result = [[[[] for i in xrange(N[0])] for j in xrange(N[1])] for k in xrange(N[2])]
    for p in array:
        i,j,k = ((p - Vmin ) / d).astype(int) # find the bin coordinates
        result[i][j][k].append(p)
    return result

# test the function
test = Vmin + np.random.rand(20,3) * DV # create 20 random points in the working volume
result = splitter(test)
for i in xrange(N[0]): 
    for j in xrange(N[1]):
        for k in xrange(N[2]):
            print "points in bin:", Vmin + np.array([i,j,k]) * d
            for p in result[i][j][k]:
                print p

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 python中的3D体积杂技。在3D numpy数组中选择x / y / z行/列 - 3D volume acrobatics in python.. selecting x/y/z rows/columns in 3D numpy arrays 在框中随机化(x,y,z)坐标 - Randomizing (x,y,z) coordinates within a box 如何将n,y,z坐标数组转换为numpy中的3D路径 - How to convert arrays of x,y,z coordinates to 3D path in numpy 在Ruby / Python中可视化x,y,z坐标? - Visualizing x,y,z coordinates in Ruby/Python? 给定Python中具有X、Y、Z坐标的数据集,如何在NumPy中生成轮廓? - Given a dataset with X, Y, Z coordinates in Python, how to generate a contour in NumPy? 查找(x,y)坐标,z通过numpy通过测试 - Finding (x,y) coordinates where z passes a test in numpy 3d将x,y,z坐标转换为3d numpy数组 - 3d coordinates x,y,z to 3d numpy array 将形状为 (x,y,z) 和 (x,) 的 numpy 数组相乘和求和 - Multiply and sum numpy arrays with shapes (x,y,z) and (x,) 给定一组在(X,Y,Z)坐标中定义的点,在任意(X,Y)处插值Z值 - Given a set of points defined in (X, Y, Z) coordinates, interpolate Z-value at arbitrary (X, Y) 如何在python(numpy)中找到2个x,y坐标数组之间的容许重叠 - How to find the tolerable overlap between 2 arrays of x,y coordinates in python (numpy)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM