Basically, two steps would be involved :
Offset all numbers by the minimum along real and imaginary axes.
Divide each by the max. magnitude. To get the magnitude of a complex number, simply use np.abs()
.
Thus, the implementation would be -
def normalize_complex_arr(a):
a_oo = a - a.real.min() - 1j*a.imag.min() # origin offsetted
return a_oo/np.abs(a_oo).max()
Sample runs for verification
Let'start with an array that has a minimum one of [0+0j]
and two more elements - [x1+y1*J]
& [y1+x1*J]
. Thus, their magnitudes after normalizing should be 1
each.
In [358]: a = np.array([0+0j, 1+17j, 17+1j])
In [359]: normalize_complex_arr(a)
Out[359]:
array([ 0.00000000+0.j , 0.05872202+0.99827437j,
0.99827437+0.05872202j])
In [360]: np.abs(normalize_complex_arr(a))
Out[360]: array([ 0., 1., 1.])
Next up, let's add an offset to the minimum element. This shouldn't change their magnitudes after normalization -
In [361]: a = np.array([0+0j, 1+17j, 17+1j]) + np.array([2+3j])
In [362]: a
Out[362]: array([ 2. +3.j, 3.+20.j, 19. +4.j])
In [363]: normalize_complex_arr(a)
Out[363]:
array([ 0.00000000+0.j , 0.05872202+0.99827437j,
0.99827437+0.05872202j])
In [364]: np.abs(normalize_complex_arr(a))
Out[364]: array([ 0., 1., 1.])
Finally, let's add another element that is at twice the distance from offsetted origin to make sure this new one has a magnitude of 1
and others are reduce to 0.5
-
In [365]: a = np.array([0+0j, 1+17j, 17+1j, 34+2j]) + np.array([2+3j])
In [366]: a
Out[366]: array([ 2. +3.j, 3.+20.j, 19. +4.j, 36. +5.j])
In [367]: normalize_complex_arr(a)
Out[367]:
array([ 0.00000000+0.j , 0.02936101+0.49913719j,
0.49913719+0.02936101j, 0.99827437+0.05872202j])
In [368]: np.abs(normalize_complex_arr(a))
Out[368]: array([ 0. , 0.5, 0.5, 1. ])