问题复现 >>> a = set() >>> b = set() >>> b.add(1) >>> a.add(b) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: unhashable type: 'set' >>> c = list(b) >>…
新版:Python 的 unhashable type 错误分析及解决 python使用set来去重是一种常用的方法. 一般使用方法如下: # int a = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0] print "orginal:", a print list(set(a)) # str a = [str(i) for i in a] print "orginal:", a print list(set(a)) 某…
d20220330 #false >>> l=[{i:i+1} for i in [1,2,3]] >>> l [{1: 2}, {2: 3}, {3: 4}] >>> d={**i for i in l} File "<stdin>", line 1 SyntaxError: dict unpacking cannot be used in dict comprehension #true >>> d…
原因是,python字典的key不支持list类型和dict类型,需要转换 错误时 将list类型强制转换成string,用"".join(list). 修改后:…
         Python : 3.7.3          OS : Ubuntu 18.04.2 LTS         IDE : pycharm-community-2019.1.3       Conda : 4.7.5    typesetting : Markdown   code coder@ubuntu:~$ source activate py37 (py37) coder@ubuntu:~$ ipython Python 3.7.3 (default, Mar 27 2…
K-Means聚类算法 def randCent(dataSet, k): m, n = dataSet.shape # numpy中的shape函数的返回一个矩阵的规模,即是几行几列 centrodids = np.zeros(k, n) for i in range(k): index = int(np.random.uniform(0, m)) # centrodids[i, :] = dataSet[index, :] return centrodids 报错TypeError: dat…
如何使用Python产生一个数组,数组的长度为1024,数组的元素全为0? 很简单啊, 使用zeros(1024) 即可实现! 如何产生一个2×1024的全0矩阵呢?是否是zeros(2,1024) ? 若是上述这种写法就会出现 TypeError: data type not understood  这种错误: 正确的写法是 zeros((2,1024)),python的二维数据表示要用二层括号来进行表示. 三维数据是否使用三层括号?试一试,果然可以正确输出!试猜一猜, 下述三层括号中的数字分…
源:DataCamp datacamp 的 DAILY PRACTICE  + 日常收集. How much is your $100 worth after 7 years? Guess the type convert Python values into any type Which one of these will throw an error? How much is your $100 worth after 7 years? Suppose you have $100, whic…
AIX-vi操作-提示Unknown terminal type的问题解决方法AIX Version 5.3$ vi /etc/profilelinux: Unknown terminal type[Hit return to continue] :q!I don't know what kind of terminal you are on - all I have is 'linux'.[Using open mode]……临时办法,下次启动失效,需要重新执行$ echo $TERMlinu…
Python提示AttributeError 或者DeprecationWarning: This module was deprecated解决方法 在使用Python的sklearn库时,发现sklearn的cross_validation不能使用,在pycharm上直接显示为被横线划掉. 运行程序: import sklearn ... X, Xt, y, yt = sklearn.cross_validation.train_test_split(X, y) 报错: AttributeE…