Skip to content
Advertisement

TypeError: unhashable type: ‘numpy.ndarray’, Counter rows

I’m trying to view the frequency of the elements in a 2d array as in the code:

JavaScript

Expected result: ({(22, 66): 2, (33, 77): 1, (55, 99): 1})

But I get:

JavaScript

Advertisement

Answer

JavaScript

Create a list of tuples: (tuples are hashable)

JavaScript

Now Counter works:

JavaScript

numpys own unique also works

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement