:
import numpy as np
A = np.asarray([400.5, 100, 700, 200, 15, 900])
B = np.asarray([500.5, 200, 500, 600.5, 8, 999])
X = np.asarray([400.5, 700, 100, 300, 15, 555, 900])
Y = np.asarray([500.5, 500,600.5, 100, 8, 555, 999])
AB = np.stack([A, B], axis=-1)
XY = np.stack([X, Y], axis=-1)
eq = AB[:, np.newaxis, :] == XY[np.newaxis, :, :]
eq = np.logical_and.reduce(eq, axis=-1)
indAB, = np.where(np.logical_or.reduce(eq, axis=1))
indXY, = np.where(np.logical_or.reduce(eq, axis=0))
print("indAB", indAB)
print("indXY", indXY)
:
indAB [0 2 4 5]
indXY [0 1 4 6]
AB XY - A B X Y, , "" . eq AB XY; np.newaxis AB XY ( , AB 1 XY 0). == . np.logical_and.reduce , "" ( A X B Y), np.logical_or.reduce , - AB XY XY AB. , np.where .
, len(A) x len(X) x 2, , , .
, . " ", ( - ). " ", , :
import numpy as np
MAX_SIZE = 2
A = np.asarray([400.5, 100, 700, 200, 15, 900])
B = np.asarray([500.5, 200, 500, 600.5, 8, 999])
X = np.asarray([400.5, 700, 100, 300, 15, 555, 900])
Y = np.asarray([500.5, 500,600.5, 100, 8, 555, 999])
AB = np.stack([A, B], axis=-1)
XY = np.stack([X, Y], axis=-1)
maskAB = np.full(len(AB), False, dtype=bool)
maskXY = np.full(len(XY), False, dtype=bool)
for iAB in range(0, len(AB), MAX_SIZE):
pAB = np.expand_dims(AB[iAB:iAB + MAX_SIZE], axis=1)
for iXY in range(0, len(XY), MAX_SIZE):
pXY = np.expand_dims(XY[iXY:iXY + MAX_SIZE], axis=0)
eq = pAB == pXY
eq = np.logical_and.reduce(eq, axis=-1)
maskAB[iAB:iAB + MAX_SIZE] |= np.logical_or.reduce(eq, axis=1)
maskXY[iXY:iXY + MAX_SIZE] |= np.logical_or.reduce(eq, axis=0)
indAB, = np.where(maskAB)
indXY, = np.where(maskXY)
print("indAB", indAB)
print("indXY", indXY)
:
indAB [0 2 4 5]
indXY [0 1 4 6]
MAX_SIZE 2, , , , (, MAX_SIZE = 10000 ). MAX_SIZE , .