pythonmappingphase

Get angle into range 0 - 2*pi - python


In my simulation i compute multiple values for a phase, for example

phi = np.linspace(-N,N,1000)

where N can be large.

Is there an easy way to map the values to the intervall [0,2pi) ?


Solution

  • Does that work ?

    import numpy as np
    import math
    
    N=10
    phi = np.linspace(-N,N,1000)
    
    phi = phi%(2*math.pi)
    
    print(phi)
    

    Output

    [2.56637061 2.58639063 ... 3.69679467 3.71681469]