Skip to content Skip to sidebar Skip to footer

Scipy Kmeans Exits With Typeerror

When running the code below, I'm getting a TypeError that says: 'File '_vq.pyx', line 342, in scipy.cluster._vq.update_cluster_means TypeError: type other than float or double not

Solution 1:

Doing:

ar = ar.reshape(scipy.product(shape[:2]), shape[2])
print(ar.dtype)

you will see, that you call kmeans with data of type uint8.

As kmeans, in theory, is defined on a d-dimensional real vector, scipy also does not like it (as given in the error)!

So just do:

ar = ar.reshape(scipy.product(shape[:2]), shape[2]).astype(float)

Casting like that is making my example run until the print, which also needs to be changed to reflect the given types.

Post a Comment for "Scipy Kmeans Exits With Typeerror"