I need to create an array of data which resembles to something like this
Table[{i, Sin[j^2*i]}, {j, 2000}, {i, 0., Pi, Pi/10000.}]
where each "row" of the array contains a list of tuples for varying values of the 'j' parameter. The time required for this computation can be calculated by the AbsoluteTiming
function, giving
{15.1485, Null}
I succeeded in using functional programming at the first level. This speeds things up. For example, the following code does the same thing as the initial one:
Table[{#1, Sin[j^2 #1]} & /@ Range[0, Pi, Pi/10000.], {j, 2000}]
but is 5 times as fast as the original one. AbsoluteTiming
returns
{3.71441, Null}
The size of these tables roughly represents the size of the data that I am currently manipulating (lots of it). Since I noticed that Table
is not the most "time-efficient" option, I would like to learn how to construct this kind of table with things like pure functions and slots (which I naively assume leads to faster code).
Table[{i, Sin[j^2 i]}, {j, 2}, {i, 0., Pi, Pi/100.}];
:Table
can take multiple iterators. $\endgroup$Table[{i, Sin[j*i]}, {i, 0., 4 Pi, 4 Pi/100.},{j,2}]
. Nevertheless, I have modified the title and updated my question accordingly. $\endgroup$t1 = Chop@Table[{i, Sin[j*i]}, {j, 2}, {i, 0., 4 Pi, 4 Pi/100.}];
andt2 = Chop@ Outer[{#2, Sin[#1 #2]} & , {1, 2}, Range[0., 4 Pi, 4 Pi/100.]];
are almost identical in timing. $\endgroup$Table
is functional programming. If what you are looking for is to speed up this code, then please edit the question and make that the main topic. $\endgroup$