Created
August 2, 2024 11:51
-
-
Save jens-andersson-2-wcar/a28fc648d94abd27425bb68356728961 to your computer and use it in GitHub Desktop.
Average bearing: one wrong way and two correct ones
This file contains hidden or 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 | |
import scipy.stats | |
# compass bearings in degrees: | |
data = [2, 356] | |
# average bearing: | |
print(np.mean(data)) # == 179.0, aka "wrong" | |
print(scipy.stats.circmean(data, high=360, low=0)) # == 359.0, aka "correct" | |
print(np.rad2deg(np.angle(np.mean(np.cos(np.deg2rad(data)) + np.sin(np.deg2rad(data)) * 1j))%(2*math.pi))) | |
# == 359.0, aka also correct, but achieving the result in an overly complex way |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment