I have a 3 D numpy array which contains elements with repetition.
counterTraj.shape
(13530, 1, 1
For example counterTraj contains such elements: I have shown few elements only:
array([[[136.]],
[[129.]],
[[130.]],
...,
[[103.]],
[[102.]],
[[101.]]])
```
I need to find frequency of different element: Example: 136 count 5 (say), 101 count 12 (say). The array elements are not fixed and changes with input data. I try following:
from collections import Counter
Counter(counterTraj)
Following error generates:
> TypeError Traceback (most recent
call last)
<ipython-input-408-e3584b29b0bd> in <module>()
11 counterTraj=np.vstack(counterTraj)
12 counterTraj=counterTraj.reshape(len(counterTraj),1,1)
---> 13 Counter(counterTraj)
/usr/lib/python3.6/collections/__init__.py in __init__(*args, **kwds) 533 raise TypeError('expected at most 1 arguments, got %d' % len(args)) 534 super(Counter, self).__init__() --> 535 self.update(*args, **kwds) 536 537 def __missing__(self, key): /usr/lib/python3.6/collections/__init__.py in update(*args, **kwds) 620 super(Counter, self).update(iterable) # fast path when counter is empty 621 else: --> 622 _count_elements(self, iterable) 623 if kwds: 624 self.update(kwds) TypeError: unhashable type: 'numpy.ndarray'
How to find occurence of element with frequency and find highest frequency element?