Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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..

share|improve this question

1 Answer 1

up vote 6 down vote accepted
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}]
share|improve this answer
    
Thanks a lot! I known that it's very easy!;) –  V_kid Mar 31 at 19:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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