Using numpy to build an array of all combinations of two arrays
In newer version of numpy (>1.8.x), numpy.meshgrid() provides a much faster implementation: @pv’s solution numpy.meshgrid() use to be 2D only, now it is capable of ND. In this case, 3D: Note that the order of the final resultant is slightly different.