1
$\begingroup$

2 Files A and B. A has 2593 lines and B has 18900000. I would like to Take A[i] and associate(added to the same line) it with 720 lines of B. Then A[1+1] associate it with the next 720 lines in B. So in the end A[2593] would be associated with the last 720 lines of file B.

I can do it with for loops, but would like a more elegant and effiecient way.

A={{1,2,3},{4,2,5},{9,11,3}...{5,2,8}} B= Same format

Any assistance or documentation would be appreciated.

Thank You Michel

$\endgroup$
  • $\begingroup$ does MapThread[Join, {A, Flatten /@ Partition[B, 720]}] work? $\endgroup$ – kglr Aug 23 at 0:38
  • $\begingroup$ is Dimensions@B {18900000,3}? $\endgroup$ – kglr Aug 23 at 1:31
  • $\begingroup$ That is not the form I am looking for, The result would be as: A[1]->B[1] A[1]->B[2] . . . . A[1]->B[720] A[2]->B[721] . . . . A[2]->B[1440] A[3]->B[1441] . . . . A[2593]->B[1866960] Thank You Michel $\endgroup$ – Michel Mesedahl Aug 23 at 1:35
  • $\begingroup$ how about Join@@MapThread[Thread[Rule@##, List, {2}] &, {A, Partition[B, 720]}]? $\endgroup$ – kglr Aug 23 at 1:38
  • $\begingroup$ It is {1866960,6} I am attempting to get it into a form for a neural Network. $\endgroup$ – Michel Mesedahl Aug 23 at 1:42
2
$\begingroup$

Try

Join @@ MapThread[Thread[Rule @ ##, List, {2}] &, 
  {A, Partition[B[[;; 720 Length @ A]], 720]}]
$\endgroup$
  • $\begingroup$ I am getting this MapThread::mptc: Incompatible dimensions of objects at positions {2, 1} and {2, 2} of MapThread[Thread[Rule[##1],List,{2}]&,{{{21,30,39,44,45,46},{5,12,16,19,45,48}},{{{1,5,20,24,28,52},{1,5,20,24,52,28},{1,5,20,28,24,52},{1,5,20,28,52,24},{1,5,20,52,24,28},{1,5,20,52,28,24},{1,5,24,20,28,52},<<37>>,{1,20,52,24,5,28},{1,20,52,24,28,5},{1,20,52,28,5,24},{1,20,52,28,24,5},{1,24,5,20,28,52},{1,24,5,20,52,28},<<670>>}}}]; dimensions are 2 and 1. $\endgroup$ – Michel Mesedahl Aug 24 at 14:45
  • $\begingroup$ @MichelMesedahl, does Join @@ MapThread[Thread[Rule @ ##, List, {2}] &, {A, Partition[B[[;; 720 Length @ A]], 720]}] work? $\endgroup$ – kglr Aug 25 at 16:19
  • 1
    $\begingroup$ Hello, This does work and it is very fast: Join @@ MapThread[Thread[Rule @ ##, List, {2}] &, {A, Partition[B[[;; 720 Length @ A]], 720]}] Thank You $\endgroup$ – Michel Mesedahl Aug 25 at 16:28

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.