Skip to content

Instantly share code, notes, and snippets.

@MattWoodhead
Created January 14, 2018 18:57
Show Gist options
  • Save MattWoodhead/61d07b3ebb8df887c30bf0ff8b9c6e88 to your computer and use it in GitHub Desktop.
Save MattWoodhead/61d07b3ebb8df887c30bf0ff8b9c6e88 to your computer and use it in GitHub Desktop.
Normalise angles (to +/-180 deg or +/- ) in a numpy array
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