Using Array and Table Functions in Mathematica. Which is best when

后端 未结 5 1980
执念已碎
执念已碎 2021-01-30 14:38

I have been mostly a Table functions user in mathematica. However I have noticed that in several examples where I used Array instead of Table to express the same result, it ran

5条回答
  •  离开以前
    2021-01-30 15:10

    Your statement:

    However I have noticed that in several examples where I used Array instead of Table to express the same result, it ran markedly faster, especially as the dimension of table grew larger.

    is not usually true for one-dimensional arrays. Take a look:

    Cl;
    Needs["PlotLegends`"]
    $HistoryLength = 0;
    a = 10^8;
    arr = {}; tab = {};
    Do[(
       arr = {First@Timing@Array[# &, a], arr};
       tab = {First@Timing@Table[i, {i, a}], tab};
       ), {10}];
    
    ListLinePlot[{Flatten@arr, Flatten@tab}, 
     AxesLabel -> {Style["Iteration", 14], Style["Time", 14]}, 
     PlotLegend -> {Style["Array", 14], Style["Table", 14]}, 
     PlotRange -> {{0, 10}, {1.6, 2}}]  
    

    enter image description here

提交回复
热议问题