Created
January 14, 2018 18:57
-
-
Save MattWoodhead/61d07b3ebb8df887c30bf0ff8b9c6e88 to your computer and use it in GitHub Desktop.
Normalise angles (to +/-180 deg or +/- ) in a numpy array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
def normalise_angles_deg(array): | |
""" Converts angles to -180 => A <= +180 """ | |
array = np.where(array<-180 , array + 360, array) | |
return np.where(array>180 , array - 360, array) | |
def normalise_angles_rad(array): | |
""" Converts angles to -Pi => A <= +Pi """ | |
array = np.where(array<-np.pi , array + 2*np.Pi, array) | |
return np.where(array>np.pi , array - 2*np.Pi, array) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment