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.

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

share|improve this question
    
You'll find helpful these answers and benchmarks: Applying And to lists of Booleans. –  Artes Mar 11 at 11:12

1 Answer 1

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
share|improve this answer
    
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. –  user12876 Mar 11 at 11:31

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.