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的更多相关文章

  1. 诡异错误二:TypeError: data type not understood

    如何使用Python产生一个数组,数组的长度为1024,数组的元素全为0? 很简单啊, 使用zeros(1024) 即可实现! 如何产生一个2×1024的全0矩阵呢?是否是zeros(2,1024) ...

  2. python报错 TypeError: a() got multiple values for argument 'name'

    [问题现象] 在一次调用修饰函数中出现了问题,折腾了一下午,一直报错 TypeError:  got multiple values for argument 只是很简单的调用 from tsu2Ru ...

  3. Python报错TypeError: '<' not supported between instances of 'str' and 'int'

    n = input() if n>=100:print(int(n)/10) else:print(int(n)*10) 报错内容: Traceback (most recent call la ...

  4. python 报错TypeError: 'range' object does not support item assignment,解决方法

    贴问题 nums = range(5)#range is a built-in function that creates a list of integers print(nums)#prints ...

  5. python报错 TypeError: string indices must be integers

    所以在读取字典的时候,最好先判断类型,然后再查看它是否已经有这样的属性: type(mydict) == type({})             #检查不是字典 如果是字典,再看看有没有这样的属性: ...

  6. 完美解决 scipy.misc.imread 报错 TypeError: Image data cannot be converted to float

    File "/home/harrison/anaconda3/lib/python3.7/site-packages/matplotlib/image.py", line 634, ...

  7. vue调用组件,组件回调给data中的数组赋值,报错Invalid prop type check failed for prop value. Expecte

    报错信息: 代码信息:调用一个tree组件,选择一些信息 <componentsTree ref="typeTreeComponent" @treeCheck="t ...

  8. appium 提示报错“TypeError: 'unicode' object is not callable”的解决方式!

    这里提到的这个报错,是小错误且容易经常会犯,有时需要特别注意使用. 目的要求结果:根据某个元素的id值获取到对应id的text值,并且将获取的text值与本身存在的text值做比较,查看text值是否 ...

  9. VUE.JS 使用axios数据请求时数据绑定时 报错 TypeError: Cannot set property 'xxxx' of undefined 的解决办法

    正常情况下在data里面都有做了定义 在函数里面进行赋值 这时候你运行时会发现,数据可以请求到,但是会报错 TypeError: Cannot set property 'listgroup' of ...

随机推荐

  1. Java集合总结(二):Map和Set

    集合类的架构图: HashMap 内部维护一个链表数组做哈希表,默认大小为16,最大值可以为2^30,默认负载因子0.75. 可以通过构造方法指定初始大小和负载因子,当键值对个数大于等于临界值thre ...

  2. 为什么我在mysql的my.cnf下找不到bind-address

    在/etc/mysql/mysql.conf.d目录下的mysqld.cnf文件

  3. 原来INF文件是干这个的

    When the drivers for a device are installed, the installer uses information in an information (INF) ...

  4. Ubuntu18.04安装和配置Django,并实现简单示例

    一.前言(系统,django介绍,window.mac.linux简单区别) Django是python开发过程最重要的web框架.因为在看的Django教学视频是在mac下安装的,我自己用的是Lin ...

  5. postman学习总结

    从网上各处学习总结,会有不足之处,后期不断补充中... 一.get\post请求参数 1.get类型 (1)选择请求方式GET (2)输入完整的URL (3)在param中填写参数,点击send发送请 ...

  6. c isnormal

    Returns whether x is a normal value: i.e., whether it is neither infinity, NaN, zero or subnormal. / ...

  7. c++ 排序,<< 运算符重载

    #include <iostream> #include <functional> #include <list> using namespace std; ost ...

  8. linux查看服务安装目录redis

    如果用命令 which redis 或者 whereis redis 都找不到安装目录, 可使用以下办法: ps -aux | grep redis  或者ps -ef|grep redis 假如得到 ...

  9. treeview判断节点是不是已存在

    /// <summary>        /// 判断treeView的节点是否已存在  treeView1.Nodes[0].Nodes        /// </summary& ...

  10. 网络1911、1912 C语言第0次作业批改总结

    网络1911.1912 C语言第0次作业批改总结 题目:C博客作业00--我的第一篇博客 一.评分规则 总分10分,每个问题都务必回答,分值都在问题后面 抄袭 - 0分 博客作业格式不规范,没有用Ma ...