Say I have following list:
listA= [u'156' u'204' u'426' u'488' u'426' u'570' u'488' u'564' u'426' u'208' u'476' u'566' u'429' u'395' u'570' u'280' u'570' u'108' u'395' u'426' u'570' u'208' u'280' u'426' u'449' u'108' u'570' u'395' u'192' u'204' u'570' u'569' u'156' u'192' u'518' u'192' u'570' u'469' u'395' u'426' u'566' u'156' u'208' u'561' u'449' u'518' u'208' u'280' u'280' u'430' u'566' u'203' u'566' u'570' u'280' u'570' u'570' u'108' u'518' u'570' u'564' u'516' u'280' u'426' u'569' u'280' u'570' u'566' u'426' u'564'u'570' u'485' u'395' u'108' u'570' u'391' u'395' u'280' u'192' u'566']
Now I am choosing randomly 10 values from listA with following numpy method:
subsample = np.random.choice(pois, 10, replace=False)
the Output forsubsample is:
[u'204' u'566' u'570' u'206' u'570' u'570' u'518' u'561' u'192' u'570']
an then I am counting same values, and saving it to a dictionary
unique, counts = np.unique(subsample, return_counts=True)
group_cat =dict(zip(unique, counts))
output of group_cat:
{u'204': 1, u'206': 1, u'561': 1, u'570': 4, u'566': 1, u'192': 1, u'518': 1}
However my aim is to count all zero occurences, which are in listA as well. My output should look as following:
{u'204': 1, u'206': 1, u'561': 1, u'570': 4, u'566': 1, u'192': 1,
u'518': 1, u'395':0, u'429':0, u'108':0, u'564':0, ....}
How can I save all not selected values in my dictionary as well?
Aucun commentaire:
Enregistrer un commentaire