I know that if I have a dictionary filled with with x = {unique : count} then I can use prop_dict = dict((k, round(v/sum(x.values()),2)) for k,v in x.items()), but I do not know how to get there from an array/list.
Here is some sample data:
arr = [0., 137., 3., 1., 1., 5., 2., 2., 8., 31., 155.,
3., 233., 72., 302., 66., 416., 1., 148., 200., 237., 238.,
354., 383., 422., 192., 48., 78., 136., 15., 111., 5., 21.]
>Solution :
Python has the collections.Counter class that will solve that for you:
In [1]: from collections import Counter
In [2]: arr = [0., 137., 3., 1., 1., 5., 2., 2., 8., 31., 155.,
...: 3., 233., 72., 302., 66., 416., 1., 148., 200., 237., 238.,
...: 354., 383., 422., 192., 48., 78., 136., 15., 111., 5., 21.]
In [3]: Counter(arr)
Out[3]:
Counter({0.0: 1,
137.0: 1,
3.0: 2,
1.0: 3,
5.0: 2,
2.0: 2,
8.0: 1,
31.0: 1,
155.0: 1,
233.0: 1,
72.0: 1,
302.0: 1,
66.0: 1,
416.0: 1,
148.0: 1,
200.0: 1,
237.0: 1,
238.0: 1,
354.0: 1,
383.0: 1,
422.0: 1,
192.0: 1,
48.0: 1,
78.0: 1,
136.0: 1,
15.0: 1,
111.0: 1,
21.0: 1})