Skip to main content
Became Hot Network Question

Create How to create an Arrayarray from All Combinations of Elementsall combinations of Vectorsthe vector components?

Say I have vectors {a,b,c} and {w,x,y,z}. How can I get Mathematica to output an array {{a,w},{a,x},{a,y},{a,z},{b,w},{b,x},{b,y},{b,z},{c,w},{c,x},{c,y},{c,z}} where we have all combinations of the vector components matched up. Obviously I can do this with some for loops but I'm hoping that I'm missing an easier way of doing this. The

Probably, the equivalent of the expand.grid function in RR. Help is much appreciated!

Create an Array from All Combinations of Elements of Vectors

Say I have vectors {a,b,c} and {w,x,y,z}. How can I get Mathematica to output an array {{a,w},{a,x},{a,y},{a,z},{b,w},{b,x},{b,y},{b,z},{c,w},{c,x},{c,y},{c,z}} where we have all combinations of the vector components matched up. Obviously I can do this with some for loops but I'm hoping that I'm missing an easier way of doing this. The equivalent of the expand.grid function in R. Help is much appreciated!

How to create an array from all combinations of the vector components?

Say I have vectors {a,b,c} and {w,x,y,z}. How can I get Mathematica to output an array {{a,w},{a,x},{a,y},{a,z},{b,w},{b,x},{b,y},{b,z},{c,w},{c,x},{c,y},{c,z}} where we have all combinations of the vector components matched up. I can do this with some for loops but I'm hoping that I'm missing an easier way of doing this.

Probably, the equivalent of the expand.grid function in R. Help is much appreciated!

Source Link
A P
  • 259
  • 7

Create an Array from All Combinations of Elements of Vectors

Say I have vectors {a,b,c} and {w,x,y,z}. How can I get Mathematica to output an array {{a,w},{a,x},{a,y},{a,z},{b,w},{b,x},{b,y},{b,z},{c,w},{c,x},{c,y},{c,z}} where we have all combinations of the vector components matched up. Obviously I can do this with some for loops but I'm hoping that I'm missing an easier way of doing this. The equivalent of the expand.grid function in R. Help is much appreciated!