数据形状是:
(675369, 3)
(675369, 3)
(670877, 3)
的意思axis=1
是xyz
坐标值。
所以想xyz
在三个数组中获得相同的值。
如何在三个数组中找到具有相同值的索引?
如果所有数组的长度相同,您可以遍历它们,直到找到所有 3 个都相同的索引。
例如(蟒蛇,O(n))
def findMatchingIndex(a, b, c):
for index, val in enumerate(a): # enumerate through a to get the index of the item we are looking at...
if val == b[index] and b[index] == c[index]: # if a = b and b = c then a = c
return index # return the first shared index we find
return -1 # or -1 for no index.
# for example...
findMatchingIndex([1, 2, 3], [2, 2, 1], [3, 2, 1]) # = 1
findMatchingIndex([1, 2, 3], [4, 5, 6], [3, 2, 1]) # = -1
编辑
但是,如果它们的长度不同,您将需要使用最小公分母,即最小长度。
def findMatchingIndex2(a, b, c):
# get the smallest size
size = sorted( [ len(a), len(b), len(c) ] )[0] # sort the lengths of the arrays and get the smallest/first one
for index in range (0, size): # go until the smallest array is done
if a[index] == b[index] and b[index] == c[index]: # if a = b and b = c then a = c
return index # return the first shared index we find
return -1 # or -1 for no index.
# for example...
findMatchingIndex2([1, 2, 3], [2, 2, 1], [3, 2, 1]) # = 1
findMatchingIndex2([1, 2, 3], [2, 3, 3], [3, 3, 3]) # = 2
findMatchingIndex2([1, 2, 3], [2, 3, 3], [3, 3]) # = -1
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句