Created
October 8, 2024 02:48
-
-
Save jongbinjung/2598cd50b67ff5877bb38a2999f4c774 to your computer and use it in GitHub Desktop.
Vectorized h3?
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
# From https://github.com/ajfriend/h3_example_package | |
import numpy as np | |
from h3_example_package.geo import latlng_to_cell_vect | |
from h3 import api | |
N = 100000 | |
lats, lngs = np.random.uniform(0, 90, N), np.random.uniform(0, 90, N) | |
res = 9 | |
lats = np.array(lats, dtype=np.float64) | |
lngs = np.array(lngs, dtype=np.float64) | |
out = np.zeros(len(lats), dtype="uint64") | |
%timeit latlng_to_cell_vect(lats, lngs, res, out) | |
# 48.6 ms ± 341 µs per loop (mean ± std. dev. of 7 runs, 10 loops each) | |
latlngs = [(float(lat), float(lng)) for lat, lng in zip(lats, lngs)] | |
%timeit [api.basic_int.latlng_to_cell(lat, lng, res=9) for lat, lng in latlngs] | |
# 57.6 ms ± 95.6 µs per loop (mean ± std. dev. of 7 runs, 10 loops each) | |
%timeit [api.numpy_int.latlng_to_cell(lat, lng, res=9) for lat, lng in latlngs] | |
# 58 ms ± 536 µs per loop (mean ± std. dev. of 7 runs, 10 loops each) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment