简体   繁体   中英

Magnitude of Complex Numbers in Array

I have the following array:

complex = [4+1j, 4+ 0j , 4 + 2j]

is there an efficient way to convert to the magnitude( like this pseudo code):

mag = np.magnitude(complex) = [sqrt(17), 4, sqrt(20)]

thanks

You want numpy.abs :

np.abs([4+1j, 4+ 0j , 4 + 2j])

Output:

array([4.12310563, 4.        , 4.47213595])
# == array([sqrt(17), sqrt(16), sqrt(20)])

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