# Complex numbers from two arrays with Real and Imaginary parts

I have two arrays, containing the real and imaginary parts of a list of complex numbers.

Re = {{Re_number1},{Re_number2},...}
Im = {Im_number1},{Im_number2},...}


I was wondering which is the smartest way to combine these two parts in a single array, containing complex numbers whose real and imaginary parts are taken from the two arrays Re and Im:

Complex = {{Re_number1 + i*Im_number1},...}

I guess there will be different ways to do that, maybe one thing to keep into account is that I will then need to make operations on these new complex numbers that I will create.

EDIT:

As @Belisarius suggested, I have tried with:

field [fullREAL_, fullIMAGINARY_] :=
Complex @@@ (Transpose@{fullREAL, fullIMAGINARY});
field[fullREAL, fullIMAGINARY] // MatrixForm


But it doesn't seem to work, although I suspect that's because I have made a syntax error...Can someone show me where? The arrays where I stored my rel and imaginary parts are created this way:

n = L = 8;
sigma = 3;
mu = 0.0;

leftREAL =
Table[{RandomVariate[
NormalDistribution[mu, Exp[-(2*Pi*k*sigma/L)^2]]]}, {k, n/2}];
rightREAL = Reverse[leftREAL] /. {x_, y_} -> {n - x, y};
fullREAL = Join[ {0.0}, Most[leftREAL], rightREAL] // MatrixForm

leftIMAGINARY =
Table[{RandomVariate[
NormalDistribution[mu, Exp[-(2*Pi*k*sigma/L)^2]]]}, {k, n/2 - 1}];
rightIMAGINARY = -Reverse[leftIMAGINARY] /. {x_, y_} -> {n - x, y};
fullIMAGINARY =
Join[ {0.0}, leftIMAGINARY, {0.0}, rightIMAGINARY] // MatrixForm

• Complex @@@ (Transpose@{re, im}) – Dr. belisarius Apr 13 '15 at 12:01
• Thanks @belisarius, I have edited my question, as I have tried to follow your instructions...but still I cannot make it! – johnhenry Apr 13 '15 at 12:17
• I assume you have numeric values for sigma, L and mu. Remove the curly braces in the first arguments of Table and drop the postfix //MatrixForm. belisarius' solution require you to have re={0,re1,re2,re3...} while you have re=MatrixForm[{0,{re1},{re2},...,{ren}}]. Similar consideration apply to imaginary parts. – LLlAMnYP Apr 13 '15 at 12:22
• You've got undefined symbols n, mu, etc. Then you probably need to ditch the MatrixForm. Pretty much you never use it in an assignment. It's for display purposes only. – Michael E2 Apr 13 '15 at 12:22
• I have included the values for sigma, L and mu – johnhenry Apr 13 '15 at 12:25

Here's working code with corrected syntax

n = L = 8;
sigma = 3;
mu = 0.0;

leftREAL =
Table[RandomVariate[
NormalDistribution[mu, Exp[-(2*Pi*k*sigma/L)^2]]], {k, n/2}];
rightREAL = Reverse[leftREAL] /. {x_, y_} -> {n - x, y};
fullREAL = Join[{0.0}, Most[leftREAL], rightREAL]

leftIMAGINARY =
Table[RandomVariate[
NormalDistribution[mu, Exp[-(2*Pi*k*sigma/L)^2]]], {k, n/2 - 1}];
rightIMAGINARY = -Reverse[leftIMAGINARY] /. {x_, y_} -> {n - x, y};
fullIMAGINARY = Join[{0.0}, leftIMAGINARY, {0.0}, rightIMAGINARY]

Complex @@@ (Transpose@{fullREAL, fullIMAGINARY})

(*{0., -0.00212203, -4.79203*10^-10, 3.36556*10^-22, -1.88384*10^-40,
3.36556*10^-22, -4.79203*10^-10, -0.00212203}*)

(*{0., 0.00201095, 3.07046*10^-10, -9.41259*10^-23, 0.,
9.41259*10^-23, -3.07046*10^-10, -0.00201095}*)

(*{0. + 0. I, -0.00212203 + 0.00201095 I, -4.79203*10^-10 +
3.07046*10^-10 I, 3.36556*10^-22 - 9.41259*10^-23 I, -1.88384*10^-40 + 0. I, 3.36556*10^-22 + 9.41259*10^-23 I, -4.79203*10^-10 - 3.07046*10^-10 I, -0.00212203 - 0.00201095 I}*)


Perhaps I'm missing something, but why not do

Most[leftREAL] + I leftIMAGINARY
rightREAL + I rightIMAGINARY


These could then be put into a single array if desired.

Alternatively

Flatten[fullREAL + I fullIMAGINARY] // MatrixForm Note that I have preemptively removed MatrixForm from the "full..." assignments and only applied it at the end as it sometimes discombobulates functions along the way.