简体   繁体   English

为两个二维 arrays 创建一个 boolean 掩码,表示 3D 点的坐标

[英]Creating a boolean mask for two 2D arrays representing coordinates of 3D points

I have two arrays, A is an (m, 3) -shape array and B is an (n, 3) -shape array with m > n (this condition is always satisfied. In fact m is at least 3 times n).我有两个 arrays,A 是一个(m, 3)形状的数组,B 是一个(n, 3)形状的数组, m > n (总是满足这个条件。实际上 m 至少是 n 的 3 倍)。 The two arrays look like this:两个 arrays 看起来像这样:

A = [[x1  y1  z1]                    |  B = [[u1  v1  w1] 
     [x2  y2  z2]                    |       [u2  v2  w2] 
     ...                             |       ...        
     ...                             |       [un  vn  wn]]   
     ...                             |
     ...                             |
     [xm  ym  zm]]                   |

(u, v, w) and (x, y, z) are coordinates of 3D points. (u, v, w)(x, y, z)是 3D 点的坐标。 All of the points in B exist in A (which contains more points, most are not in B). B 中的所有点都存在于 A 中(其中包含更多点,大多数不在 B 中)。 One thing to note is that the order of appearance of points in B is not necessarily the same in A , meaning that, for the sake of illustration, [u1 v1 w1] can be at position (row) 256 , [u2 v2 w2] at 15 , [u3 v3 w3] at 569001 , etc.需要注意的一点是B 中点的出现顺序在 A 中不一定相同,这意味着,为了说明起见, [u1 v1 w1]可以在 position (row) 256[u2 v2 w2]15[u3 v3 w3]569001等。

Another important detail: the coordinates are floats, and if two points correspond, then uk = xj, vk = yj, wk = zj (meaning that the points have the exact position, and are not just close to each other).另一个重要的细节:坐标是浮点数,如果两个点对应,则 uk = xj, vk = yj, wk = zj(这意味着这些点具有精确的 position,并且不只是彼此靠近)。

I want to create a Boolean mask with the same size as A that will be used later in a code, so that mask_A = [True, False, False, False, True,..., False] where True means that the point also exists in B, and False is put when the point does not appear in B.我想创建一个 Boolean 掩码,其大小与稍后将在代码中使用的 A 相同,因此mask_A = [True, False, False, False, True,..., False]其中True表示该点也存在于 B 中,当该点不存在于 B 中时置为False

I also want to do with it without any loops , because the sizes are huge and the procedure of creating the mask is repeated multiple times.我也想在没有任何循环的情况下使用它,因为尺寸很大,并且创建蒙版的过程会重复多次。 I have no problem changing the type of the arrays (turning them into lists, sets, whatever...) as long as it gets the job done and quickly.只要能快速完成工作,我就可以更改 arrays 的类型(将它们变成列表、集合等……)。

I have found multiple answers dealing with masks and 2D arrays, but none of them answer my question.我找到了多个处理面具和 2D arrays 的答案,但没有一个回答我的问题。

Thank you.谢谢你。

As both of them are numpy arrays, you can use the function numpy.intersect1d由于它们都是 numpy arrays,您可以使用 function Z2EA9510C37FdF6F89E4ZCB41FFF721

_, indices_ar1, _ = numpy.intersect1d(ar1, ar2, assume_unique=False, return_indices=True)

I don't know you application but maybe this is enough for you.我不知道你的申请,但也许这对你来说已经足够了。 If not you just have to convert these indices to the binary mask.如果不是,您只需将这些索引转换为二进制掩码。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM