0
$\begingroup$

basically I have a group of data in dimension (21*51), I managed to generate the name of the file and Imported into a Table

 name = Table[StringTemplate["/Users/Projekt/output/log/b7_t`t`_a`a`.dat", InsertionFunction -> (ToString@NumberForm[#, {2, 2}] &)]@<|"t" -> 0.01 k, "a" -> 0.01 l|>, {k, 1, 21}, {l, 0, 50}];
 data = Table[Import[name[[i, j]]], {i, 1, 21}, {j, 1, 51}]

The dimension of both name and data are

 In[28]= Dimensions[data]
Out[29]= {21, 51}

Now, each file has a list of numbers, and I intend to do the calculation of accumulative moving average of each file, and put them under one table for later use, I know for each single file the method would simply be for example

cma = Accumulate[data1]/Range[1, Length[data1]]

but when I change data into data[[i,j]] and define {i,1,21},{j,1,51}, it will simply break down, much appreciate if anyone can give me some help!

$\endgroup$
7
  • $\begingroup$ There's MovingAverage. $\endgroup$
    – corey979
    Dec 16 '16 at 10:59
  • $\begingroup$ I just calculate the average with respect to the current number of data, not by a fixed window $\endgroup$
    – Gvxfjørt
    Dec 16 '16 at 11:06
  • $\begingroup$ cma = Table[ Accumulate[data[[i]]]/Range[1, Length[data[[i]]]], {i, 1, Length@data}] $\endgroup$
    – corey979
    Dec 16 '16 at 11:22
  • $\begingroup$ Hi@corey979, I'm not sure if the code works or not, because it consumes too much memory, my 16Gb ram is simply not enough, is there a computationally cheaper way to do this? $\endgroup$
    – Gvxfjørt
    Dec 16 '16 at 22:41
  • $\begingroup$ This code, for data = RandomReal[1, {21, 51}] having Dimensions@data == {21, 51}, runs in 0.002418 sec (AbsoluteTiming). I cannot know what are you doing there; maybe you have some old definitions, corrupted data, or your data has some other format than follows from your question. $\endgroup$
    – corey979
    Dec 16 '16 at 22:51
1
$\begingroup$

By the method mentioned in the question, the actual Dimension for data would be {21,51,Length[data],1}.
So here's the solution

Table[Accumulate[data[[i, j]]]/Range[1, Length[data[[i, j]]]], {i, 1, 21}, {j, 1, 50}]

Thanks corey979

$\endgroup$

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.