I want to write a code like
X={};
index=1;
max=3;
For[i=1,i<=2,i++,
For[j=1,j<=2,j++,
X[[index]]=i*j;
index++
]
]
But I am not getting correct result. Can anyone please help
Summary of methods. (Add yours if you have one not already here.)
Bob Hanlon
Array[#1*#2 &, {3, 3}] // Flatten
Table[i*j, {i, 3}, {j, 3}] // Flatten
Simon Rochester
KroneckerProduct @@ Range[{3, 3}] // Flatten
Range[3] Range[{3, 3, 3}] // Flatten
Accumulate /@ Transpose@Range@ConstantArray[3, 3] // Flatten
m_goldberg
Range[3] ConstantArray[Range[3], 3] // Flatten
x=Array[#1*#2 &, {3, 3}] // Flattenorx=Table[i*j, {i, 3}, {j, 3}] // Flatten$\endgroup$Forloop. $\endgroup$Tablesolution proposed by @bob-hanlon $\endgroup$Flatten@KroneckerProduct[#, #]&@Range@3$\endgroup$