I have two arrays of (x,y) coordinates. After performing a mathematical operation on them, I ask the program which of the answers are less than 300.
I would also like it to tell me which two pairs of (x,y) coordinates (one from array a and one from array b) were used to compute this answer. How can I do this?
Nb: the arrays' contents are random and their lengths are chosen by the user (as you will see below).
Here is my code:
#Create arrays
xy_1 = [(random.randint(0,1000), random.randint(0,1000)) for h in range((int(raw_input(“Type your first array’s range: “)))]
a = array([xy_1])
xy_2 = #same as above
b = array([xy_2])
(If the user chooses for xy_1 to have 3 pairs and xy_2 to have 2 pairs, the output would look like this:
a[(1,5),(300,70),(10,435)]
b[(765,123),(456,20)]
with different numbers every time as it's a random number generator.)
#Perform mathematical operation
for element in a:
for u in element:
for element in b:
for h in element:
ans = (((u[0] - h[0])**2) + ((u[1] - h[1])**2))
if ans <= 300:
#Problem here print "a: " + str(np.nonzero(u)[0]) + "b: " + str(np.nonzero(h)[0]) + "is less than 300"
else:
#and here print "a: " + str(np.nonzero(u)[0]) + "b: " + str(np.nonzero(h)[0]) + "is more than 300"
Currently, the output looks like this:
a: [0 1] b: [0 1] is less than 300
or
a: [0 1] b: [0 1] is more than 300
but as I said above, I would like it to tell me the index (or whatever it's called for arrays) of each (x,y) pair in a and b, such that it looks like this:
a: 15 b: 3 is less than 300
(if it were the 15th pair of coordinates in a and the 3rd pair in b that created an outcome that was less than 300).
I have tried using zip with itertools.count, but it wound up repeating the iteration far too many times, so that's out.