0
$\begingroup$

To help distinguish the various dimensions, I have a model which outputs a vector in a series of time intervals, I then construct a list of these models. Next, I would like to compute the outer product of the vector at each time step. I think I can do something like the following

tdim = 100;
vecdim = 3;
modeldim = 2;

(*veclist is supposed to represent the output for 2 models*)
veclist = Table[v[model, t, a], {model, modeldim}, {t, tdim}, {a, vecdim}];

outerproduct[x_, y_] := Outer[Times, x, y];
MapThread[outerproduct, {veclist, veclist}, 2]

I think this does the right thing. It does not mix the models or the time steps. As far as I can tell it is taking the outer product at the appropriate level. However, I would like to be able to do this in the case where model 1 and model 2 have a different number of time steps and I can't see a neat way to do this. If I do the same as above but for 2 models with a different number of time steps, I get an error because the rank of the list has changed:

tdim1 = 3;
tdim2 = 4;
veclist1 = Table[v1[model, t, a], {model, 1, 1}, {t, tdim1}, {a, vecdim}];
veclist2 = Table[v2[model, t, a], {model, 2, 2}, {t, tdim2}, {a, vecdim}];
veclistall = Join[veclist1, veclist2];
MapThread[outerproduct, {veclistall, veclistall}, 2]

For the problem I have in mind these lists are much much larger, so finding an efficient way of doing this would be a great help. Any suggestions would be hugely appreciated

$\endgroup$
1

1 Answer 1

1
$\begingroup$

What I don't understand is if you don't want the models mixed anyway, why are you joining them in one matrix veclistall? I think the code below does what you want

MapThread[Outer[Times, #1, #2] &, {#, #}] & /@ veclistall
$\endgroup$
1
  • $\begingroup$ Great! Thank you! They are all in one list because I have a lot of models and I need to perform the same basic operations on all of them (I have a few hundred models, each with more than 2000 time steps and vector dimension can be as much as 100). I was hoping that in the long run this would make things faster. $\endgroup$
    – user12876
    Commented Mar 11, 2014 at 11:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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