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的更多相关文章
- 诡异错误二:TypeError: data type not understood
如何使用Python产生一个数组,数组的长度为1024,数组的元素全为0? 很简单啊, 使用zeros(1024) 即可实现! 如何产生一个2×1024的全0矩阵呢?是否是zeros(2,1024) ...
- python报错 TypeError: a() got multiple values for argument 'name'
[问题现象] 在一次调用修饰函数中出现了问题,折腾了一下午,一直报错 TypeError: got multiple values for argument 只是很简单的调用 from tsu2Ru ...
- 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 ...
- 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 ...
- python报错 TypeError: string indices must be integers
所以在读取字典的时候,最好先判断类型,然后再查看它是否已经有这样的属性: type(mydict) == type({}) #检查不是字典 如果是字典,再看看有没有这样的属性: ...
- 完美解决 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, ...
- vue调用组件,组件回调给data中的数组赋值,报错Invalid prop type check failed for prop value. Expecte
报错信息: 代码信息:调用一个tree组件,选择一些信息 <componentsTree ref="typeTreeComponent" @treeCheck="t ...
- appium 提示报错“TypeError: 'unicode' object is not callable”的解决方式!
这里提到的这个报错,是小错误且容易经常会犯,有时需要特别注意使用. 目的要求结果:根据某个元素的id值获取到对应id的text值,并且将获取的text值与本身存在的text值做比较,查看text值是否 ...
- VUE.JS 使用axios数据请求时数据绑定时 报错 TypeError: Cannot set property 'xxxx' of undefined 的解决办法
正常情况下在data里面都有做了定义 在函数里面进行赋值 这时候你运行时会发现,数据可以请求到,但是会报错 TypeError: Cannot set property 'listgroup' of ...
随机推荐
- date对象设置set
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- C#中的@符号的使用
一 字符串中的用法 字符@表示,其后的字符串是个“逐字字符串”(verbatim string). @只能对字符串常量作用. 1.用于文件路径 string s_FilePath ="C:\ ...
- 13、生命周期-InitializingBean和DisposableBean
13.生命周期-InitializingBean和DisposableBean InitializingBean接口 package org.springframework.beans.factory ...
- 008_STM32之_keil编译内存大小解析
Program Size: Code=28784 RO-data=6480 RW-data=60 ZI-data=3900 的含义 1. Code: 程序所占用的FLASH大小,存储在FLASH. ...
- Density of Power Network(ZOJ 3708)
Problem The vast power system is the most complicated man-made system and the greatest engineering i ...
- .net Core使用 MongoDB
1.安装mogodb windows版本下载地址:https://www.mongodb.com/download-center/v2/community 查看mongod.conf文件,找到绑定的I ...
- CComboBoxEx添加图像CImageList无法正常显示
<1>给控件 CComboBox绑定变量 .cpp中 DDX_Control(pDX, IDC_COMBO_PHOTO_IMG, m_ComboBoxPhotoImg); CComboBo ...
- 8月清北学堂培训 Day6
今天是杨思祺老师的讲授~ 图论 双连通分量 在无向图中,如果无论删去哪条边都不能使得 u 和 v 不联通, 则称 u 和 v 边双连通: 在无向图中,如果无论删去哪个点(非 u 和 v)都不能使得 u ...
- HDU 1114 Piggy-Bank ——(完全背包)
差不多是一个裸的完全背包,只是要求满容量的最小值而已.那么dp值全部初始化为inf,并且初始化一下dp[0]即可.代码如下: #include <stdio.h> #include < ...
- java基础篇之Object类
1.Object类是所有类的超类 2.Object类的equals方法 public boolean equals(Object obj) {return (this == obj);} equals ...