Message Boards Message Boards


Strange behavior of Transpose in Mathematica 12.3 for Windows

Posted 3 months ago
4 Replies
1 Total Likes

Transpose is used in tree different ways. It spents much time, except when it is added AbsoluteTiming. Why? Thanks. Guillermo

Very slow

Transpose[{Range[10^5], Range[10^5]}]


Evaluate[Transpose[{Range[10^5], Range[10^5]}]]


Evaluate[Transpose[{Range[10^5], Range[10^5]}]] // AbsoluteTiming
4 Replies
Posted 3 months ago

The time is spent rendering the large output in the notebook. Add ; to suppress the output

(tr = Transpose[{Range[10^5], Range[10^5]}];) // AbsoluteTiming
(* {0.000537, Null} *)

(tr = Evaluate[Transpose[{Range[10^5], Range[10^5]}]];) // AbsoluteTiming
(* {0.000352, Null} *)
Posted 3 months ago


Any idea why Evaluate runs in about 60% of the time as the non-evaluate version?


Posted 3 months ago

Hi Mike,

The times are small and AbsoluteTiming is elapsed time which depends on what else is running on the machine. Replace AbsoluteTiming with RepeatedTiming to get a more accurate measurement. There is very little difference. Or use BenchmarkPlot.

tr = Transpose[{#, #}] &;
trEval = Evaluate[Transpose[{#, #}] &];
r = Range[10^7];

BenchmarkPlot[{tr, trEval}, r[[;; #]] &, 10^Range[7]]

enter image description here

Posted 3 months ago


Thanks. I can trust the space-time continuum again. :)

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract