I have a list of floats, and I want to know how many duplicates are in it.
I have tried with this:
p = t_gw.p(sma, m1, m2) #p is a 1d numpy array
p_list = list(p)
dup = set([x for x in p_list if p_list.count(x) > 1])
print dup
I have also tried to use collections.counter, but I always get the same error
TypeError: unhashable type: 'numpy.ndarray'
I've looked around in similar questions, but I can't understand what hashable means, why a list (or numpy array) is not hashable and what kind of type should I use.
Your numpy-array is two-dimensional. So
list(p)
does not do, what you expect. Uselist(p.flat)
instead.Or (mis)use numpy's histogram function: