Python报错:TypeError: data type not understood

Posted wqiong

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python报错:TypeError: data type not understood相关的知识,希望对你有一定的参考价值。

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: data type not understood
错误在第三行centrodids = np.zeros(k, n)
原来numpy.zeros的用法用错了
numpy.zeros(shape,dtype = float,order =‘C‘ )
返回给定形状和类型的新数组,并用零填充。
shape:整数或者整数元组例如:(2,1)
dtype:数据类型,可选
order:{‘C’,‘F’}可选,默认C
所以应该吧第三行改成centrodids = np.zeros((k, n))

以上是关于Python报错:TypeError: data type not understood的主要内容,如果未能解决你的问题,请参考以下文章

pandas报错 TypeError: Cannot perform ‘rand_‘ with a dtyped [object] array and scalar of type [bool](代码

TypeError: ### is null,空指针导致的报错

pandas报错处理:TypeError: Empty 'DataFrame': no numeric data to plot

python报错 TypeError: string indices must be integers

python3报错:TypeError: can't concat bytes to str

Python_报错:TypeError: Tuple or struct_time argument required