I have a numpy array of integer tuples of length 3 (x) and an numpy array of integer tuples of length 2 (y).
x = numpy.array([[3, 4, 5], [5, 12, 13], [6, 8, 10], [7, 24, 25]])
y = numpy.array([[3, 4], [4, 5], [3, 5], [5, 12]])
I am trying to compare the elements inside the array y: [a, b] and [b, c] and [a, c], which are subsets of the same element [a, b, c] in the array x. I call this union of functions. Below is my hard method to find a pool. This is not too good for my arrays that contain 200K minimal elements.
def union(x, y):
for intx in range (len(x)):
cond1 = cond2 = cond3 = 0
for inty in range (len(y)):
if (y[inty][0] == x[intx][0] and y[inty][1] == x[intx][1]):
print ("condition 1 passed")
cond1 = 1
if (y[inty][0] == x[intx][1] and y[inty][1] == x[intx][2]):
print ("condition 2 passed")
cond2 = 1
if (y[inty][0] == x[intx][0] and y[inty][1] == x[intx][2]):
print ("condition 3 passed")
cond3 = 1
if (cond1 & cond2 & cond3):
print("union found with ", x[intx])
cond1 = cond2 = cond3 = 0
return
>>> union(x,y)
condition 1 passed
condition 2 passed
condition 3 passed
union found with [3 4 5]
condition 1 passed
UPDATE # 1: Example 1: this set of x and y does not have a union:
x = numpy.array([[21, 220, 221]])
y = numpy.array([[21, 220], [20, 21], [220,3021], [1220,3621], [60,221]])
UPDATE # 2: Example 2: this collection of x and y does not have a union:
x = numpy.array([[43, 924, 925]])
y = numpy.array([[43, 924], [924, 1643], [924,4307], [72, 925]])
Example 3: Here is a set of x and y that have a union [4, 8, 16].
x = numpy.array([[4, 8, 16], [8, 4, 16]])
y = numpy.array([[4, 8], [8, 16], [4, 16]])
Example 4: Here is the set of x and y that have a union [12, 14, 15].
x = numpy.array([[12, 13, 15], [12, 14, 15]])
y = numpy.array([[12, 14], [12, 13], [12, 15], [14, 15]])
. , x y [a, b, c],
x = numpy.array([[a, b, c], ...])
y = numpy.array([[a, b], [b, c], [a, c],...])
y
y = numpy.array([[...[b, c], [a, c], ... [a, b]])
, : ?
, numpy.logical_and , x1 x2 .
if isisisoint, . qaru.site/questions/1546480/...