I would like to generate a set of data of matrix of size 1000 x 1000 x 1000 in a region defined by 0 outside the sphere of radius r=100 centered in the coordinate (500, 500, 500), and number 1 inside the sphere.
n = 1000;(*Matrix dimension*)
f = Compile[{i, j, k},If[(i-500)^2 + (j - 500)^2 + (k - 500)^2 <= (10)^2, 1, 0]];
ic = ParallelTable[f[N@i, N@j, N@k], {i, n}, {j, n}, {k, n}];
Next, to apply Fast Fourier Transform to data.
fftshift[dat_?ArrayQ, k : (_Integer?Positive | All) : All] := Module[{dims = Dimensions[dat]},
RotateRight[dat,If[k === All, Quotient[dims, 2],Quotient[dims[[k]], 2] UnitVector[Length[dims], k]]]];
ict = Table[fftshift@ic[[i]], {i, Length[ic]}];
Finally to export the data.
Export["ic50.mat", ict]
However, the time to conclude the process is huge.
How to optimize this to reduce run time?
Fourierfor that. Applied to a multidimensional tensor, it applies FFT to each of its slots. – Henrik Schumacher Nov 16 '21 at 22:43