Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: iteration over a 0-d array, using numpy

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.

like image 497
Devinity Avatar asked Jan 18 '14 00:01

Devinity


1 Answers

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()))
like image 137
user6655984 Avatar answered Oct 06 '22 13:10

user6655984