I would like to efficiently upsample a multidimensional array.
It's a 5000*5 matrix where each element is a submatrix 12*12 and it is that 12*12 matrix I want upsampled (to 24*24). The upsampling should just replicate the value.
I have some code to illustrate:
arr = Table[Random[], {5000}, {5}, {12}, {12}];
ans = Map[ArrayFlatten,
Map[{{#, #}, {#, #}} &, arr, {4}], {2}]; // AbsoluteTiming
(* {2.6501516, Null} *)
ans // Dimensions
(* {5000, 5, 24, 24} *)
ans[[3, 4, 1 ;; 5, 1 ;; 5]] // MatrixForm
Is there a faster way? I am using Mathematica version 8, but could be persuaded to upgrade if a new version makes this much faster.
I am also thinking of going down the GPU route at some point, so anything that was suitable for GPU would also be helpful.
Riffle[]
if it's just a simple duplication you want? $\endgroup$ArrayResample[]
- reference.wolfram.com/language/ref/ArrayResample.html, although it actually seems slow... $\endgroup$