简体   繁体   中英

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 R exp{j O}

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!

you can get your R and O directly in numpy:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM