Reputation: 377
I'm using this code, straight from the scikit-learn page. It creates a dictionary:
symbol_dict = {
'TOT': 'Total',
'XOM': 'Exxon',
'CVX': 'Chevron',}
symbols, names = np.array(symbol_dict.items()).T
But I get an error:
TypeError: iteration over a 0-d array
This code is straight from the example code, so I have no idea what's going wrong.
Upvotes: 6
Views: 14630
Reputation:
As user2357112 said, in Python 3 dict.items()
returns a dictionary view object rather than a list of key-value pairs (the difference is explained here). Wrapping it in list()
creates a list which is something NumPy can turn into an array:
np.array(list(symbol_dict.items()))
Upvotes: 2