0

Say, I have 9 circles, each containing a few thousands discrete points (coordinates).

I want to write a matrix where circle 1 points belong to the first row, circle 2 points belong to the second row, etc.

How do I find all possible combinations of such matrix rows, such that:

  • all rows still only contain coordinates from their corresponding circles;
  • each row only uses one point from its circle at a time (no different point combinations within a row).

Is there a better way to do it rather than having 9 nested loops and appending matrices into a list in which every matrix is a list and each row within a matrix is a list, too?

Thank you!

update: I'll try to make myself clearer.

Say, I have a list, each element of each is a list containing the coordinates in its corresponding circle.

[[x1,y1],[x2,y2],[x3,y3]] = [ [[1,2],[3,4]], [[5,6],[7,8]], [[9,10],[11,12]] ]

where x1, y1 are the coordinates of the points in circle 1. In this case there are only 3 circles and each of them contains only 2 points.

Now I want to make a matrix where rows correspond to circles, and columns correspond to coordinates (column 1 is x, column 2 is y).

I want all possible combinations of points, so that I get matrices like these:

possibility 1: [[1,2], [5,6], [9,10]]

possibility 2: [[3,4], [7,8], [11,12]]

possibility 3: [[1,2], [7,8], [9,10]]

possibility 4: [[3,4], [5,6], [11,12]]

etc.

Note that row n always corresponds to circle n. How do I find all possible matrix combinations of this form?

(In reality I need to solve a linear programming problem in spherical coordinates, but I hope I simplified the problem well enough. I could draw a picture if you'd like)

daria
  • 9
  • 2
  • 2
    I don't understand what you want to do. Can you add an example of input/output (obviously scaled down from thousands of points per circle/row)? – Blorgbeard Dec 07 '19 at 00:26
  • @Blorgbeard hope it's a bit clearer now! – daria Dec 07 '19 at 00:43
  • Ok, I think I get it now - this is basically the same problem as [this question](https://stackoverflow.com/questions/798854/all-combinations-of-a-list-of-lists), except you're dealing with coordinates instead of single numbers. But the same solution will work. Here's an example: https://repl.it/repls/VigorousDarkblueFormats – Blorgbeard Dec 07 '19 at 03:57

0 Answers0