Skip to content

Commit 8214100

Browse files
committed
BUG: sparse vs non sparse centers
The 'toarray()' method is not present on arrays
1 parent 16244a0 commit 8214100

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

sklearn/cluster/k_means_.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,9 @@ def _mini_batch_step(X, x_squared_norms, centers, counts,
869869
if n_reassigns:
870870
print("[_mini_batch_step] Reassigning %i cluster centers."
871871
% n_reassigns)
872-
centers[to_reassign] = new_centers.toarray()
872+
if sp.issparse(new_centers) and not sp.issparse(centers):
873+
new_centers = new_centers.toarray()
874+
centers[to_reassign] = new_centers
873875

874876
# implementation for the sparse CSR reprensation completely written in
875877
# cython

0 commit comments

Comments
 (0)