python使用
2016-06-14 16:30
281 查看
numpy.shape
range
numpy.sum() 求和
numpy.mean() 均值
numpy.var() 方差
numpy.std() 标准差
参考 python 科学计算学习一:numpy快速处理数据(3)
numpy.max() 最大值
numpy.min() 最小值
numpy.argmax() 最大值的下标
numpy.argmin() 最小值的下标
numpy.sort() 排序
numpy.argsort() 排序后的数据原来位置的下标
pickle.load(file) Read a string from the open file object file and interpret it as a pickle data stream, reconstructing and returning the original object hierarchy
14.
>>> import numpy as np >>> a = np.array([1, 2, 3, 4]) >>> a.shape (4,) >>> a.shape[0] 4 >>> c = np.array([[1, 2, 3, 4],[4, 5, 6, 7], [7, 8, 9, 10]]) >>> c.shape (3, 4) >>> c.shape[0] 3 >>> c.shape[1] 4
range
>>> range(1,5) #代表从1到5(不包含5) [1, 2, 3, 4] >>> range(1,5,2) #代表从1到5,间隔2(不包含5) [1, 3] >>> range(5) #代表从0到5(不包含5) [0, 1, 2, 3, 4]
numpy.sum() 求和
>>> a array([[6, 7, 1, 6], [1, 0, 2, 3], [7, 8, 2, 1]]) >>> np.sum(a) 44 >>> np.sum(a,axis=0) array([14, 15, 5, 10]) >>> np.sum(a,axis=1) array([20, 6, 18]) >>> np.sum(a,axis=-1)
numpy.mean() 均值
>>> a array([[6, 7, 1, 6], [1, 0, 2, 3], [7, 8, 2, 1]]) >>> np.mean(a) 3.6666666666666665 >>> np.mean(a,axis=0) array([ 4.66666667, 5. , 1.66666667, 3.33333333])
numpy.var() 方差
>>> np.var(a) 7.7222222222222223 >>> np.var(a,axis=0) array([ 6.88888889, 12.66666667, 0.22222222, 4.22222222])
numpy.std() 标准差
>>> np.std(a,axis=0) array([ 2.62466929, 3.55902608, 0.47140452, 2.05480467])
参考 python 科学计算学习一:numpy快速处理数据(3)
numpy.max() 最大值
numpy.min() 最小值
numpy.argmax() 最大值的下标
numpy.argmin() 最小值的下标
numpy.sort() 排序
>>> a array([[6, 7, 1, 6], [1, 0, 2, 3], [7, 8, 2, 1]]) >>> a.sort() >>> a array([[1, 6, 6, 7], [0, 1, 2, 3], [1, 2, 7, 8]]) >>> np.sort(a,axis=0) array([[0, 1, 2, 3], [1, 2, 6, 7], [1, 6, 7, 8]])
numpy.argsort() 排序后的数据原来位置的下标
>>> np.argsort(a,axis=0) array([[1, 1, 1, 1], [0, 2, 0, 0], [2, 0, 2, 2]])
pickle.load(file) Read a string from the open file object file and interpret it as a pickle data stream, reconstructing and returning the original object hierarchy
Welcome To PyCrust 0.7.2 - The Flakiest Python Shell Sponsored by Orbtech - Your source for Python programming expertise. Python 2.2.1 (#1, Aug 27 2002, 10:22:32) [GCC 3.2 (Mandrake Linux 9.0 3.2-1mdk)] on linux-i386 Type "copyright", "credits" or "license" for more information. >>> import cPickle as pickle >>> t1 = ('this is a string', 42, [1, 2, 3], None) >>> t1 ('this is a string', 42, [1, 2, 3], None) >>> p1 = pickle.dumps(t1) >>> p1 "(S'this is a string'\nI42\n(lp1\nI1\naI2\naI3\naNtp2\n." >>> print p1 (S'this is a string' I42 (lp1 I1 aI2 aI3 aNtp2 . >>> t2 = pickle.loads(p1) >>> t2 ('this is a string', 42, [1, 2, 3], None) >>> p2 = pickle.dumps(t1, True) >>> p2 '(U\x10this is a stringK*]q\x01(K\x01K\x02K\x03eNtq\x02.' >>> t3 = pickle.loads(p2) >>> t3 ('this is a string', 42, [1, 2, 3], None)
14.
相关文章推荐
- Python动态类型的学习---引用的理解
- Python3写爬虫(四)多线程实现数据爬取
- 垃圾邮件过滤器 python简单实现
- 下载并遍历 names.txt 文件,输出长度最长的回文人名。
- install and upgrade scrapy
- Scrapy的架构介绍
- Centos6 编译安装Python
- 使用Python生成Excel格式的图片
- 让Python文件也可以当bat文件运行
- [Python]推算数独
- Python中zip()函数用法举例
- Python中map()函数浅析
- Python将excel导入到mysql中
- Python在CAM软件Genesis2000中的应用
- 使用Shiboken为C++和Qt库创建Python绑定
- FREEBASIC 编译可被python调用的dll函数示例
- Python 七步捉虫法