I have a numpy array with letters "a", "b" or "c",
import numpy as np
my_array = np.array(["a", "a", "c", "c", "a"]) # In this example "b" is not present
I want to fuild a function f that counts the unique records of each letter present in the array, for my example f should respond [3, 0, 2] meaning that "a" has appeared 3 times, "b" 0 times and "c" 2 times.
I'm looking for solution (if it possible) that use numpy functions and not explicit for loops over the array. Maybe a kind of group by
source https://stackoverflow.com/questions/71056055/count-unique-register-in-numpy-array
Comments
Post a Comment