Search code examples
pythonnumpyarray-broadcasting

Numpy project array of m X coords and array of n Y coords into mxn list of (X,Y) coords


Effectively I want two nested for loops over xs and ys, where each x is paired with each y:

xs = [0,1,2]
ys = [2,3]


desiredResult = [[0,2],[1,2],[2,2],[0,3],[1,3],[2,3]]

Wondering if there's a nice numpy solution?


Solution

  • Pythonic comprehension is probably good enough for this one:

    coords = [(x,y) for x in xs for y in ys]