After reading this Converting NumPy array into Python List structure?, I have:
import numpy as np
print np.array(centroids).tolist()
print "here\n"
print old_centroids
print type(np.array(centroids).tolist())
print type(old_centroids)
which gives:
[[-0.30485176069166947, -0.2874083792427779, 0.0677763505876472], ...,[0.09384637511656496, -0.015282322735474268, -0.05854574606104108]]
here
[array([-0.30485176, -0.28740838, 0.06777635]), ..., array([-0.03415291, -0.10915068, 0.07733185]), array([ 0.09384638, -0.01528232, -0.05854575])]
<type 'list'>
<type 'list'>
However, when I am doing:
return old_centroids == np.array(centroids).tolist()
I am getting this Error:
return old_centroids == np.array(centroids).tolist()
ValueError: The truth value of an array with more than one element is ambiguous.
How to fix this?
The type of centroids
is <type 'numpy.ndarray'>
and they are computed like this:
from sklearn import decomposition
centroids = pca.transform(mean_centroids)
Note, that without PCA, I would just do:
return old_centroids == centroids
EDIT_0:
Check if two unordered lists are equal suggests set()
, thus I did:
return set(old_centroids) == set(np.array(centroids).tolist()) # or set(centroids)
and got:
TypeError: unhashable type: 'list'