Re: Need to speed up a matrix calculation
- To: mathgroup at smc.vnet.net
- Subject: [mg105708] Re: Need to speed up a matrix calculation
- From: Ray Koopman <koopman at sfu.ca>
- Date: Wed, 16 Dec 2009 06:18:14 -0500 (EST)
- References: <hg7v8m$eo0$1@smc.vnet.net>
On Dec 15, 4:25 am, Garapata <warsaw95... at mypacks.net> wrote: > I have a calculation, which I want to do in a more direct, elegant, > and faster calculating way. > > Start with 3 variables and > 2 matrices: > > intervals = 10; > samples = 5; > measurements = 3; > > p = Array[a, {intervals -1, samples, measurements}]; > m = Array[b, {samples, intervals}]; > > In real life these matrices will get very large, hence the reason I > want speed. > > The matrices represent values associated with a time series during an > intermediate state of calculation. So as a preliminary step to the > next calculation, to make them the same time length, I drop a column > from matrix m. This enables me to use the previous valves in m with > the current values in p in the subsequent calculation: > > mMost = Drop[w, None, -1]; > > This also shortens the length the next line, the one I need help with. > > composition = (Transpose[p[[#]]] . mMost[[All, #]] ) * 5 / > Total[mMost[[All, #]]] & /@ Range[Length[p]] > > This works, but will likely get quite slow as I increase the number of > intervals, samples, and measurements. I'd like a more direct way to > do this. The above seems bit like making map like an iterative loop, > kind of cheating at functional programing. > > Any help much appreciated. This is a little simpler, and doesn't need 'mMost': c = m[[All,#]].p[[#]]& /@ Range@Length@p * 5 / Most@Total@m ; c === composition True