Python
蝈蝈家小夫君
一枚专注数据挖掘、数据分析的小白丁
展开
-
Python中亲和度分析时defaultdict的一种典型算法
在做亲和度分析时,需要统计用户选择产品A之后同时选择产品B的支持度,此时需要使用defaultdict函数。 通过defaultdict(int) 生成了一个默认为0的带key(此时的key为同时包含A、B的tuple,即key = (A,B))的数据字典。eg.import numpy as npfrom collections import defaultdictX转载 2017-04-06 23:03:39 · 671 阅读 · 0 评论 -
Python中多个数组行合并及列合并的几个简单方法
采用numpy快速将两个矩阵或数组合并成一个数组:import numpy as np数组a = [[1,2,3],[4,5,6]]b = [[1,1,1],[2,2,2]]1、数组纵向合并1)c = np.vstack((a,b))c = array([[1, 2, 3], [4, 5, 6],原创 2017-04-06 21:31:11 · 56864 阅读 · 1 评论 -
Python中的sorted函数以及operator.itemgetter函数
operator.itemgetter函数operator模块提供的itemgetter函数用于获取对象的哪些维的数据,参数为一些序号(即需要获取的数据在对象中的序号),下面看例子。a = [1,2,3] >>> b=operator.itemgetter(1) //定义函数b,获取对象的第1个域的值>>> b(a) 2 >>> b=operator.itemge转载 2017-05-08 15:17:39 · 477 阅读 · 2 评论 -
计算numpy中array的行和列
import numpy as npx = np.array([[1,2,5],[2,3,5],[3,4,5],[2,3,6]])# 输出数组的行和列数print(x.shape) # (4, 3)# 只输出行数print(x.shape[0]) # 4# 只输出列数print (x.shape[1]) # 3原创 2017-04-27 16:51:28 · 22735 阅读 · 0 评论