Effective Pandas by Tom Augspurger

Effective Pandas by Tom Augspurger

Author:Tom Augspurger
Language: eng
Format: epub
Published: 2016-07-06T23:04:34+00:00


The second implementation uses NumPy. Aside from numpy having a builtin deg2rad convenience function (which is probably a bit slower than multiplying by a constant $ rac{\pi}{180}$), basically all we’ve done is swap the math prefix for np. Thanks to NumPy’s broadcasting, we can write code that works on scalars or arrays of conformable shape.

def gcd_vec(lat1, lng1, lat2, lng2): ''' Calculate great circle distance. http://www.johndcook.com/blog/python_longitude_latitude/ Parameters ---------- lat1, lng1, lat2, lng2: float or array of float Returns ------- distance: distance from ``(lat1, lng1)`` to ``(lat2, lng2)`` in kilometers. ''' # python2 users will have to use ascii identifiers ϕ1 = np.deg2rad(90 - lat1) ϕ2 = np.deg2rad(90 - lat2) θ1 = np.deg2rad(lng1) θ2 = np.deg2rad(lng2) cos = (np.sin(ϕ1) * np.sin(ϕ2) * np.cos(θ1 - θ2) + np.cos(ϕ1) * np.cos(ϕ2)) arc = np.arccos(cos) return arc * 6373



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.