Q:
top_10 = np.percentile(dictionary.values(), 90)
TypeError: unsupported operand type(s) for *: 'dict_values' and 'float'
A:
在 python3 中,dict.values返回一个dict_values对象,它不是 alist或tuple。尝试将其强制为列表。
a = list(dictionary.values())
top_10 = np.percentile(a, 90)
The class is written in Python 2, where Dict.values() returns a list, but this was updated in Python 3 to return a dictionary view, described here: https://docs.python.org/3/library/stdtypes.html#dict-views
网友评论