Lynx
Lynx

Reputation: 25

How to create the table of frequency for a list that contains arrays

I have a list that has a few hundred thousand arrays of the same size. I need to remove the first element in each array and then create a table of frequency using np.unique(my_array,return_counts=True).

For instance, consider

data = [[0,1,5,6,3,4,5],[2,3,1,2,4,0,5],[9,7,0,2,4,0,3],[8,7,1,7,4,0,2]]

How do I find the number of times each of the unique values comes up in the above list data. Since my data is big, I need a fast method.

Upvotes: 1

Views: 102

Answers (1)

Quang Hoang
Quang Hoang

Reputation: 150745

You can turn data into numpy array for advanced slicing:

np.unique(np.array(data)[:,1:], return_counts=True)

Output:

(array([0, 1, 2, 3, 4, 5, 6, 7]), array([4, 3, 3, 3, 4, 3, 1, 3]))

Upvotes: 2

Related Questions