0

There are multiple questions based on this topic like -

Using numpy to build an array of all combinations of two arrays

Cartesian product of x and y array points into single array of 2D points but these are applicable to values inside arrays and not on the rows of arrays

but what i want is combination of rows in way like --- row0 to row 1 , row 0 to row 2 , 0 to 3, 0 to 4 then 1 to 2 , 1 to 3, 1 to 4 and so on

a=np.array([
                 [  0. ,  338.2 ],
                 [  1. ,  339.45],
                 [  2. ,  339.2 ],
                 [  3. ,  340.7 ],
                 [  4. ,  340.15]

                 ])

output must be -

[  0.  338.2] [  1.   339.45]
[  0.  338.2] [  2.  339.2]
[  0.  338.2] [  3.  340.7]
[  0.  338.2] [  4.   340.15]

[  1.   339.45] [  2.  339.2]
[  1.   339.45] [  3.  340.7]
[  1.   339.45] [  4.   340.15]

[  2.  339.2] [  3.  340.7]
[  2.  339.2] [  4.   340.15]

[  3.  340.7] [  4.   340.15]

itertools.combinations works but it is really slow if size of array increases so looking for numpy approach

  • 1
    Provide a [**minimal reproducible example**](https://stackoverflow.com/help/minimal-reproducible-example). "Implement this feature for me" is off-topic for this site. You have to _make an honest attempt_, and then ask a _specific question_ about your algorithm or technique. Please take the [tour](https://stackoverflow.com/tour), read [what's on-topic here](https://stackoverflow.com/help/on-topic), [How to Ask](https://stackoverflow.com/questions/how-to-ask), and the [question checklist](https://meta.stackoverflow.com/q/260648). And show what you have tried with `itertools.combinations`. – aneroid Feb 25 '22 at 07:19
  • While there are several ways of producing the equivalent of itertools.product, combinations is harder, since it has groups of varying size, 4,3, 2,1. Building on `triu` as suggested by the linked answers may be the best. Rectangles are a better fit than triangles in numpy. – hpaulj Feb 25 '22 at 07:57

0 Answers0