Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

np.sum parallelization with axis #31

Open
ehsantn opened this issue Aug 22, 2017 · 0 comments
Open

np.sum parallelization with axis #31

ehsantn opened this issue Aug 22, 2017 · 0 comments

Comments

@ehsantn
Copy link

ehsantn commented Aug 22, 2017

We need to parallelize np.sum with axis argument to enable the following simpler version of k-means:

@numba.njit(parallel=True)
def kmeans(A, numCenter, numIter):
    N, D = A.shape
    centroids = np.random.ranf((numCenter, D))

    for l in range(numIter):
        dist = np.array([[sqrt(np.sum((A[i,:]-centroids[j,:])**2))
                                for j in range(numCenter)] for i in range(N)])
        labels = np.array([dist[i,:].argmin() for i in range(N)])
        centroids = np.array([np.sum(A[labels==i], 0)/np.sum(labels==i)
                                for i in range(numCenter)])

    return centroids
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant