2018年4月16日

python2和python3的不同

摘要: 在输出方面 Old: print "The answer is", 2*2 New: print("The answer is", 2*2) Old: print x, # Trailing comma suppresses newline New: print(x, end=" ") # Appe 阅读全文

posted @ 2018-04-16 21:59 Aaron12 阅读(107) 评论(0) 推荐(0) 编辑

Python中文件读取方法read(),readline(),readlines()

摘要: Python中文件读取方法read(), readline()以及readlines()的区别: 1. read()方法 >>> file = open('filename') # filename: 文件名 >>> type(file.read()) <type 'str'> # 即得到的是文件的 阅读全文

posted @ 2018-04-16 20:41 Aaron12 阅读(1641) 评论(0) 推荐(0) 编辑

python中的get函数

摘要: get()函数作用 以classCount.get(voteIlabel,0)为例: classCount.get(voteIlabel,0)返回字典classCount中voteIlabel元素对应的值,若无,则进行初始化 若不存在voteIlabel,则字典classCount中生成voteIl 阅读全文

posted @ 2018-04-16 11:27 Aaron12 阅读(3178) 评论(0) 推荐(0) 编辑

python中的sum函数

摘要: sum函数 对于二维数组,默认表示将所有元素相加,axis=1表示将每一行向量相加,axis=0表示将每一列向量相加。 阅读全文

posted @ 2018-04-16 11:02 Aaron12 阅读(552) 评论(0) 推荐(0) 编辑

python中的shape函数

摘要: shape函数 在看机器学习实战这本书时,遇到shape(0)函数,愣是没看懂怎么回事,装了软件后后,实验了几把,原来是这样子: 读取矩阵的长度,比如shape[0]就是读取矩阵第一维度的长度。它的输入参数可以使一个整数表示维度,也可以是一个矩阵 shape[0]就是计算行数,shape[1]就是计 阅读全文

posted @ 2018-04-16 10:49 Aaron12 阅读(4108) 评论(0) 推荐(1) 编辑

python中的tile函数

摘要: tile函数 在看机器学习实战这本书时,遇到numpy.tile(A,B)函数,愣是没看懂怎么回事,装了numpy模块后,实验了几把,原来是这样子: 按照行或列重复A,B次,这里的B可以时int类型也可以是数组类型。 阅读全文

posted @ 2018-04-16 10:39 Aaron12 阅读(537) 评论(0) 推荐(0) 编辑

导航