A Python library with an implementation of k-means clustering on 1D data.
The core algorithm is wrote on julia by pabloferz and Raf in discourse, which is a translation of C++ code.
Here we use jnumpy for exporting julia function to python function.
from jl_kmeans1d import jl_cluster
from kmeans1d import cluster
import numpy as np
X1 = np.random.rand(1000)
%timeit jl_cluster(X1, 32) # 2.18 ms
%timeit cluster(X1, 32) # 6.15 ms
X2 = np.random.rand(1000000)
%timeit jl_cluster(X2, 32) # 4.68s
%timeit cluster(X2, 32) # 9.38s