0

I'm not sure what the proper terminology is for this but I would like to combine two arrays such that the resulting array has paired each item from A with each item from B:

A = [1, 2, 3]
B = [1, 2, 3]

result = [[1,1],
          [1,2],
          [1,3],
          [2,1],
          [2,2],
          [2,3],
          [3,1],
          [3,2],
          [3,3]]

Is there a numpy method for accomplishing this or do I need to generate a for loop and build a whole new array?

smci
  • 29,564
  • 18
  • 109
  • 144
P-Rod
  • 439
  • 1
  • 4
  • 18
  • Not within numpy, but within itertools (itertools.product). – sascha Oct 14 '16 at 23:51
  • Related: [Numpy: cartesian product of x and y array points into single array of 2D points](http://stackoverflow.com/questions/11144513/numpy-cartesian-product-of-x-and-y-array-points-into-single-array-of-2d-points) – Moses Koledoye Oct 14 '16 at 23:54

1 Answers1

2

Generate that using:

[(x,y) for x in A for y in B]
sramij
  • 4,627
  • 5
  • 29
  • 53