5
$\begingroup$

I am new to Mathematica. And I'm sorry for my English.
I have created a matrix ($6 \times 4$) and an array ($1 \times 4$). I want to get another matrix that will have the first element from the array combined with all the first elements in all the lines. And the second element will be combined with all the second elements in all the lines of the matrix. I have the following data:

Z = {{ 1,  3, 3, 7}, {8, 6, 6, 3}, {3, 5, 6, 13}, 
     {15, 15, 9, 4}, {1, 1, 3, 6}, {9, 4, 3,  2}}

t = {{129600, 30240}, {30240, 10080}, {10080, 1440}, {1440, 0}}

And I'd like to get this:

{{{{129600, 30240}, 1}, {{30240, 10080}, 3}, {{10080, 1440}, 3}, {{1440, 0}, 7}},
 {{{129600, 30240}, 8}, {{30240, 10080}, 6}, {{10080, 1440}, 6}, {{1440, 0}, 3}}, 
 {{{129600, 30240}, 3}, {{30240, 10080}, 5}, {{10080, 1440}, 6}, {{1440, 0}, 13}}, 
 {{{129600, 30240}, 15}, {{30240, 10080}, 15}, {{10080, 1440}, 9}, {{1440, 0}, 4}}, 
 {{{129600, 30240}, 1}, {{30240, 10080}, 1}, {{10080, 1440}, 3}, {{1440, 0}, 6}}, 
 {{{129600, 30240}, 9}, {{30240, 10080}, 4}, {{10080, 1440}, 3}, {{1440, 0}, 2}}}

I've done it with the help of For. But it's not so convenient..

$\endgroup$
6
$\begingroup$
Transpose[{t, #}] & /@ Z
{{{{129600, 30240}, 1}, {{30240, 10080}, 3}, {{10080, 1440}, 3}, {{1440, 0}, 7}},   
  {{{129600, 30240}, 8}, {{30240, 10080}, 6}, {{10080, 1440}, 6}, {{1440, 0}, 3}}, 
  {{{129600, 30240}, 3}, {{30240, 10080}, 5}, {{10080, 1440}, 6}, {{1440, 0}, 13}}, 
  {{{129600, 30240}, 15}, {{30240, 10080}, 15}, {{10080, 1440},9}, {{1440, 0}, 4}}, 
  {{{129600, 30240}, 1}, {{30240, 10080}, 1}, {{10080, 1440}, 3}, {{1440, 0}, 6}}, 
  {{{129600, 30240}, 9}, {{30240, 10080}, 4}, {{10080, 1440}, 3}, {{1440, 0}, 2}}}

But generaly you can use Table, it is fast and clear what it is doing:

Table[{t[[i]], Z[[j, i]]}, {j, 6}, {i, 4}]
$\endgroup$
  • $\begingroup$ Thanks a lot! I known that it's very easy!;) $\endgroup$ – V_kid Mar 31 '14 at 19:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.