# Using Table to iterate over two lists element by element instead of as a matrix

So I have two lists generated in the following fashion, I don't know if it's the most efficent way to get these, but that's beside the point right now.

Nlayer = 6;
n = 0;
layernumber = Table[n = n + (Mod[i, 2]), {i, 1, 2*Nlayer}]
n = 1;
interfacenumber = Table[n = n + (Mod[i, 2]), {i, 0, 2*Nlayer-1}]


Which returns:

{1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6}

{1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7}


And I'm trying to get the Table function to apply the i-th value of each list to two different functions X and Y, getting a list of the same length as above. What I have right now is the following (which is incorrect, it returns a 12x12 matrix instead of a 1x12 table):

Table[X[i]*Y[j], {i,layernumber}, {j,interfacenumber}];


In other words, I want it to return the 12 values that would be computed below into a list. Later, this will be expanded well beyond 12 values and I want to just expand the initial list instead of typing this out many more times.

X*Y
X*Y
X*Y
X*Y
X*Y
X*Y
X*Y
X*Y
X*Y
X*Y
X*Y
X*Y


• try (X/@layernumber)( Y/@interfacenumber)?
– kglr
Oct 17, 2020 at 5:43
• If you have to use Table, you can try Table[X[layernumber[[i]]]*Y[interfacenumber[[i]]], {i, Length@layernumber} ]
– kglr
Oct 17, 2020 at 6:42
• ... or Table[X[i], {i,layernumber}] * Table[Y[j], {j,interfacenumber}]
– kglr
Oct 17, 2020 at 6:53
• That last one actually seems pretty obvious in hindsight. Thank you for the response! Oct 17, 2020 at 14:59

Maybe this?

layernumber = Accumulate[Mod[Range[1, 2 Nlayer], 2]];
interfacenumber = 1 + Accumulate[Mod[Range[0, 2 Nlayer - 1], 2]];

• MapThread[X[#1]*Y[#2] &, {layernumber, interfacenumber}] Oct 17, 2020 at 6:42
Table[X[i], {i,layernumber}] * Table[Y[j], {j,interfacenumber}]