Answers for "counts of unique values in rows of given 2D array numpy"

0

counts of unique values in rows of given 2D array numpy

mat5 = np.array([['a', 'g', 'c'], 
         		 ['a', 'b', 'c'], 
         		 ['f', 'c', 'c']])
val, cnts = np.unique(mat5, return_counts=True)
dict_unique = {k: v for k, v in zip(val, cnts)}
""" result: {'a': 2, 'b': 1, 'c': 4, 'f': 1, 'g': 1} """
Posted by: Guest on September-13-2021

Code answers related to "counts of unique values in rows of given 2D array numpy"

Code answers related to "TypeScript"

Browse Popular Code Answers by Language