Title: cmath.phase array support
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.9
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: kolibril13, mark.dickinson
Priority: normal Keywords:

Created on 2019-07-25 06:41 by kolibril13, last changed 2019-07-26 07:52 by mark.dickinson. This issue is now closed.

Messages (2)
msg348428 - (view) Author: Hendrik (kolibril13) Date: 2019-07-25 06:41
It would be nice if cmath.phase supports arrays like this: 
import cmath
import numpy as np

z=255*np.ones((3,3)) * np.exp(1j * np.pi*np.ones((3,3)))

def get_k_amp_array(z):
    return abs(z)

def get_k_ph_array(z):
    return np.array([[cmath.phase(z_row) for z_row in z_col] for z_col in z ])

amp_array=  get_k_amp_array(z)
ph_array=   get_k_ph_array(z)

msg348481 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2019-07-26 07:52
I think you want numpy.angle (

NumPy is a third-party library, so it doesn't make sense to have the math or cmath functions be aware of NumPy arrays; none of the other math or cmath functions work on arrays. Generally for this sort of thing you want to look for a solution in NumPy or SciPy.
Date User Action Args
2019-07-26 07:52:17mark.dickinsonsetstatus: open -> closed
resolution: rejected
messages: + msg348481

stage: resolved
2019-07-25 08:11:21xtreaksetnosy: + mark.dickinson

versions: + Python 3.9, - Python 3.7
2019-07-25 06:41:14kolibril13create