3

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.

Saullo G. P. Castro
  • 56,802
  • 26
  • 179
  • 234
pbreach
  • 16,049
  • 27
  • 82
  • 120
  • 1
    The end of your question is not so clear. Can you provide some examples of what you expect? – daouzli Jun 16 '14 at 12:37
  • possible duplicate of [Using numpy to build an array of all combinations of two arrays](http://stackoverflow.com/questions/1208118/using-numpy-to-build-an-array-of-all-combinations-of-two-arrays) – huon Jun 16 '14 at 12:39

2 Answers2

7

What you want is itertools.product():

from itertools import product

list(product(a, b))
#[(71, 43), (71, 42), (75, 43), (75, 42)]
Saullo G. P. Castro
  • 56,802
  • 26
  • 179
  • 234
0

Just do two for loops that are nested and go over both arrays for i=0 to len(a) do for j=0 to len(b) do out.add(coordinate(a[i],b[j]);

in need of help
  • 1,606
  • 14
  • 27