0

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!

Drago
  • 3
  • 2
  • First, know that you can make the counters work automatically by using `for count_arr, arr in enumerate(data)` and `for count_item, itm in enumerate(arr)`. – Guimoute Dec 01 '20 at 11:32

1 Answers1

0

you can get your R and O directly in numpy:

R = np.abs(z), O = np.angle(z)
shcrela
  • 76
  • 4