下面的代码没有任何问题,在Python 2.7,但是在Python 3.4.3,抛出TypeError: iteration over a 0-d array
python3字典,值列表
import numpy as np
def c1():
mat=[]
mat.append(np.array(map(float,np.random.rand(7))))
return mat
mylist=[]
mydict_={}
mydict_['dog']=c1()
mydict_['big']=c1()
justKeys={label:1 for label in list(mydict_.keys())}
for idx, word in enumerate(justKeys.keys()):
mylist.append(np.array(map(float, mydict_[word][0])))
我应该怎么才能在做两到列表mylist
python2.7和3.4获得相同的结果?
我的猜测将是.keys()从http://blog.labix.org/2008/06/27/watch-out-for-listdictkeys-in-python-3 – darwindave
谢谢。添加copy()。keys()不能解决问题。 – superMind