
python
暴走吧少年
这个作者很懒,什么都没留下…
展开
-
python——实现决策树分类
# -*- coding: utf-8 -*-from sklearn import tree#################################################################### #输入简单数据#"读入数据"X = [[0, 0], [1, 1]]Y = [0, 1]"训练数据"原创 2017-05-04 15:06:02 · 1810 阅读 · 0 评论 -
Python2.7——生成任意范围任意精度的随机数
# -*- coding: utf-8 -*-import numpy as nprandom = np.random.RandomState(0)#RandomState生成随机数种子for i in range(200):#随机数个数 a = random.uniform(-0.1, 0.1)#随机数范围 print round(a, 2)#随机数精度要求原创 2017-06-08 20:05:03 · 14887 阅读 · 0 评论 -
python——二维列表一维列表的互相转换
二维列表转一维列表from compiler.ast import flattena=[[1,2],[5,6]]print(flatten(a)) 结果:[1, 2, 5, 6]一维列表转二维列表a=[1,2,5,6]b=[3,4,8,9]print(zip(a,b)) 结果: [(1, 3原创 2017-06-08 15:45:37 · 11187 阅读 · 3 评论 -
ValueError: could not convert string to float的处理方式
平台:PyCharm遇到如下问题: data.append([float(tk) for tk in tokens[:-1]])ValueError: could not convert string to float原因:很可能是你的数据中含有\t,即退格键解决办法:1、选择任意两个数据之间间隙2、CTRL+R3、替换为一个空原创 2017-05-04 21:53:06 · 148217 阅读 · 5 评论 -
pyhton——列表转换为数组
import numpy as npX=[[1,2,3,4],[5,6,7,8],[9,0,11,12]]'列表转换为数组'Y=np.array(X)print(Y)#输出结果# [[ 1 2 3 4]# [ 5 6 7 8]# [ 9 0 11 12]]原创 2017-05-04 15:33:16 · 45754 阅读 · 4 评论 -
python3——UnicodeDecodeError: 'gbk' codec can't decode byte 0xad in position 840: illegal
错误: UnicodeDecodeError: 'gbk' codec can't decode byte 0xad in position 840: illegal multibyte sequence解决办法:f = open('1.txt', 'r', encoding="utf8")buff = f.read()f.close()注意事项:utf8不要写成utf-8,我就是因...原创 2018-04-09 16:43:24 · 1651 阅读 · 0 评论