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 ...
随机推荐
- 分页控件Webdiyer.MvcPager
MVC 1.安装控件 install-package Webdiyer.MvcPager 2.Cotroller using System; using System.Collections.Gene ...
- 长脖子鹿放置【洛谷P5030】二分图最大独立集变形题
题目背景 众周所知,在西洋棋中,我们有城堡.骑士.皇后.主教和长脖子鹿. 题目描述 如图所示,西洋棋的“长脖子鹿”,类似于中国象棋的马,但按照“目”字攻击,且没有中国象棋“别马腿”的规则.(因为长脖子 ...
- Bluetooth M590 mouse problem Ubuntu
I restart it in the terminal, and it works: Code: $ sudo -i # bluetoothctl [bluetooth]# power off [b ...
- 请问如何上传带图片的word
Chrome+IE默认支持粘贴剪切板中的图片,但是我要发布的文章存在word里面,图片多达数十张,我总不能一张一张复制吧?Chrome高版本提供了可以将单张图片转换在BASE64字符串的功能.但是无法 ...
- python 序列通用操作
通用序列操作:索引:greeting=hellogreeting[0] 分片:number[1,2,3,4,5,6]number[3:6]number[3:6:1] 序列相加:[1,2,3] + [4 ...
- Codeforces Round #571 (Div. 2)
A. Vus the Cossack and a Contest 签. #include <bits/stdc++.h> using namespace std; int main() { ...
- Django—Ajax
Ajax-get url url(r'^ajax_add/', views.ajax_add), url(r'^ajax_demo1/', views.ajax_demo1), 视图 def ajax ...
- Ubuntu14.04 打开关闭图形桌面
使用 Ctrl+Alt+t 打开命令行界面 #关闭桌面 sudo service lightdm stop #恢复桌面 sudo service lightdm start Ctrl+Alt+F1 可 ...
- 多层树级关系的json,递归删除空值的数据
data =[{ "name": "省", "children":[ { "name": "市区", ...
- ICEM—倾斜孔
原视频下载:https://yunpan.cn/cS3UGMEscrYpL 访问密码 839b