I am using a numpy array to hold a list of ordered pairs (representing grid coordinates). The algorithm I am writing needs to check if a newly generated ordered pair is already in this array. Below is a schematic of the code:
cluster=np.array([[x1,y1]])
cluster=np.append(cluster,[[x2,y2]],axis=0)
cluster=np.append...etc.
new_spin=np.array([[x,y]])
if new_spin in cluster==False:
do something
The problem with this current code is that it gives false positives. If x or y appear in the cluster, then new_spin in cluster evaluates as true. At first I thought a simple fix would be to ask if x and y appear in cluster, but this would not ensure that they appear as an ordered pair. To make sure they appear as an ordered pair I'd have to find the indices where x and y appear in cluster and compare them, which seems very clunky and inelegant, and I'm certain there must be a better solution out there. However, I have not been able to work it out myself.
Thanks for any help.
scipy.spatial.cKDTreeif the current bugs in numpy are too annoying.