I have latitude and longitude coordinates in two separate arrays:
a = np.array([71,75]) b = np.array([43,42])
How can I easily find all possible points made up of these coordinates?
I’ve been messing around with itertools.combinations:
In [43]: list(itertools.combinations(np.concatenate([a,b]), r=2)) Out[43]: [(71, 75), (71, 43), (71, 42), (75, 43), (75, 42), (43, 42)]
but this doesn’t work for me because the points (71,75)
and (43,42)
are latitude/latitude and longitude/longitude pairs.
What I would like to have is this:
Out[43]: [(71, 43), (71, 42), (75, 43), (75, 42)]
The a and b arrays will eventually be of a larger size but will be kept the same size as they are latitude/longitude pairs.
Advertisement
Answer
What you want is itertools.product()
:
from itertools import product list(product(a, b)) #[(71, 43), (71, 42), (75, 43), (75, 42)]