Reputation: 77
I have a numpy array from strings and I want to count the same strings. Is it possible? Here is my code:
import numpy as np
import sys
arr = np.array(sys.stdin.read().split(), dtype = '>U20')
print(arr)
Upvotes: 1
Views: 1639
Reputation: 3186
Try this :
import collections, numpy
collections.Counter(arr)
Or
unique, counts = numpy.unique(arr, return_counts=True)
dict(zip(unique, counts))
Upvotes: 4