If I had a numpy array in the form of
[[0. 1. 1. 1. 1.],
[1. 0. 0. 0. 0.],
[1. 0. 0. 0. 0.],
[1. 0. 0. 0. 0.],
[1. 0. 0. 0. 0.],
[0. 1. 1. 1. 1.]]
is there a way to determine the frequency of these binary arrays?
Using the example listed above, the frequencies would be something like [1.0.0.0.0] - 4, [0.1.1.1.1] - 2. I've tried using np.unique, but that returns the counts of just unique numbers which isn't super helpful in this case.
from collections import Counter
counts = Counter(map(tuple, arr))
map(tuple, arr) converts each row of the array to a tuple which is hashable and thus can be stored in a mapping like Counter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With