I have latitude and longitude coordinates in two separate arrays:
JavaScript
x
3
1
a = np.array([71,75])
2
b = np.array([43,42])
3
How can I easily find all possible points made up of these coordinates?
I’ve been messing around with itertools.combinations:
JavaScript
1
8
1
In [43]:
2
3
list(itertools.combinations(np.concatenate([a,b]), r=2))
4
5
Out[43]:
6
7
[(71, 75), (71, 43), (71, 42), (75, 43), (75, 42), (43, 42)]
8
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:
JavaScript
1
4
1
Out[43]:
2
3
[(71, 43), (71, 42), (75, 43), (75, 42)]
4
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()
:
JavaScript
1
5
1
from itertools import product
2
3
list(product(a, b))
4
#[(71, 43), (71, 42), (75, 43), (75, 42)]
5