Search code examples
pythonarraysimplementationcomplex-numbers

Python : Transforming a complex array to polar form


I have a np.array with shape (300,300) with complex values a+bj. I would like to transform each element to the polar form Rexp{jO}

I've tryied

cmath.polar(data)

But doesn't work for array, so I try something like that

complexe = np.zeros((len(data),len(data[0])))
count_arr = 0
for arr in data:
    count_item = 0
    for itm in arr:
        complexe[count_arr][count_item] = cmath.polar(itm)
        count_item = count_item +1
    count_arr = count_arr +1

It doesn't work because the output of cmath.polar is a tuple (I think).

I am a beginner in python so any help will be welcome!


Solution

  • you can get your R and O directly in numpy:

    R = np.abs(z), O = np.angle(z)