I am desperately looking for an effective way to check if two 2D numpy arrays intersect.
So, I have two arrays with an arbitrary number of 2D arrays, for example:
A=np.array([[2,3,4],[5,6,7],[8,9,10]])
B=np.array([[5,6,7],[1,3,4]])
C=np.array([[1,2,3],[6,6,7],[10,8,9]])
All I need is True, if there is at least one vector intersecting with another one from another array, otherwise false. Therefore, it should give such results:
f(A,B) -> True
f(A,C) -> False
I'm a little new to python, and first I wrote my program with Python lists, which works, but of course is very inefficient. The program takes several days to complete, so I'm working on a solution now numpy.array, but these arrays are really not that easy to use.
Here is some context about my program and Python list solution:
, , - 3 . http://en.wikipedia.org/wiki/Self-avoiding_walk. , , (, , 1000 ), , :
"" N:
X=[]
for i in range(0,N+1):
X.append((i,0,0))
:
- ( "pivotelement" )
- ( , )
- 9 (3 * 3 90 °, 180 °, 270 °)
- ,
- → , else → .
1.-6. (, 1000, ~ 5000 ), . :
def PivotFold(chain):
randPiv=random.randint(1,N)
Pivot=chain[randPiv]
C=[]
intersect=False
for j in range (0,N+1):
C.append((chain[j][0]-Pivot[0],chain[j][1]-Pivot[1],chain[j][2]-Pivot[2]))
rotRand=random.randint(1,18)
if rotRand==1:
for j in range (randPiv,N+1):
C[j]=(-C[j][1],C[j][0],C[j][2])
if C[0:randPiv].__contains__(C[j])==True:
intersect=True
break
elif rotRand==2:
for j in range (randPiv,N+1):
C[j]=(C[j][1],-C[j][0],C[j][2])
if C[0:randPiv].__contains__(C[j])==True:
intersect=True
break
...etc
if intersect==False:
Shizz=C
else:
Shizz=chain
return Shizz
PivotFold () X . , , , ^^ , numpyarrays , , ...