Hi I want to be able to count the occurrences of items from my list by indexes of a nested list.
That is if my list is
keys = ['One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight',
'Nine', 'Ten', 'Eleven', 'Twelve', 'Thirteen', 'Fourteen', 'Fifteen']
and my nested list looks like:
[['Three' 'One' 'Ten']
['Three' 'Five' 'Nine']
['Two' 'Five' 'Three']
['Two' 'Three' 'Eight']
['One' 'Three' 'Nine']]
How many times does 'One' occur at index 0 etc for each item, is what I want to know.
I am using numpy arrays to build list and am creating output from weighted random. I want to be able to run the test over say 1000 lists and count the index occurrences to determine how the changes I make elsewhere in my program affect the end result.
I have found examples such as https://stackoverflow.com/a/10741692/461887
import numpy as np
x = np.array([1,1,1,2,2,2,5,25,1,1])
y = np.bincount(x)
ii = np.nonzero(y)[0]
zip(ii,y[ii])
# [(1, 5), (2, 3), (5, 1), (25, 1)]
But this appears not to work with nested lists. Also been looking under indexing in the numpy cookbook - indexing and histogram & digitize in the example list but I just can't seem to find a function that could do this.
Updated to include example data output:
Assunming 100 deep nested lists
{'One': 19, 'Two': 16, 'Three': 19, 'Four': 11, 'Five': 7, 'Six': 8, 'Seven' 4, 'Eight' 3,
'Nine' 5, 'Ten': 1, 'Eleven': 2, 'Twelve': 1, 'Thirteen': 1, 'Fourteen': 3, 'Fifteen': 0}
Or as in treddy's example
array([19, 16, 19, 11, 7, 8, 4, 3, 5, 1, 2, 1, 1, 3, 0])