introduction to python for statistics,analysis笔记3
一、产生数组和矩阵
1、linspace(start,end,number),产生在start和end数之间number个数
>>> x = linspace(, , )
>>> x
array([ ., ., ., ., ., ., ., ., ., ., .])
2、logspace(start,end,number) 产生number个数,在10**start,10**end之间,相当于指数函数,在x轴平均分成number个数,求指数。
和10**linspace(start,end,number)效果一样
3、arange(l,u,s)
4、meshgrid()
>>> x = arange()
>>> y = arange()
>>> X,Y = meshgrid(x,y)
>>> X
array([[, , , , ],
[, , , , ],
[, , , , ]])
>>> Y
array([[, , , , ],
[, , , , ],
[, , , , ]])
5、ix_(a,b)不规则选取元素,其中a,b可以是列表或元组
>>> x = reshape(arange(25.0),(,))
>>> x
array([[ ., ., ., ., .],
[ ., ., ., ., .],
[ ., ., ., ., .],
[ ., ., ., ., .],
[ ., ., ., ., .]])
>>> x[ix_([,],[,,])] # Rows & , cols , and
array([[ ., ., .],
[ ., ., .]])
>>> x[:,:] # Same, standard slice
array([[ ., ., .],
[ ., ., .]])
>>> x[ix_([,],[,,])] # No slice equiv
二、近似
1、around, round
x=np.random.randn(3)
print x
print np.around(x)
print np.around(x,2)#近似精度为2位小数
[ 0.23073931 1.08865135 -0.95564268]
[ 0. 1. -1.]
[ 0.23 1.09 -0.96]
2、floor(x)、ceil(x)、
三、统计特性
1/sum,计算和
a=np.reshape(np.arange(),(,));
print a,'\n'
print np.sum(a),'\n'
print np.sum(a,),'\n'
print np.sum(a,)
[[ ]
[ ]] [ ] [ ]
2/prod跟sum一样的特性,他是计算乘积的
a=np.reshape(np.arange(,),(,));
print a,'\n'
print np.prod(a),'\n'
print np.prod(a,),'\n'
print np.prod(a,),'\n'
[[ ]
[ ]] [ ] [ ]
3、exp、log--相当于ln()、log10、sqrt、square、absolute, abs、sign都是对元素的操作
a=np.random.randn(,);
print a,'\n'
print np.abs(a)
print np.sign(a)
[[-0.35632202 -0.56913468 -0.5054189 ]
[-0.13182024 1.62914028 1.57704769]] [[ 0.35632202 0.56913468 0.5054189 ]
[ 0.13182024 1.62914028 1.57704769]]
[[-. -. -.]
[-. . .]]
4、对于复数的运算,下列运算也是元素的运算
- real(A)或A.real,复数的实部
- imag(A)或A.imag,复数的虚部
- conj(A), conjugate,共轭复数
5、unique(A)是对所有元素操作,相当于python中的set(),去重效果
6、in1d(A,B)
>>> x = arange(10.0)
>>> y = arange(5.0,15.0)
>>> in1d(x,y)
array([False, False, False, False, False, True, True, True, True, True], dtype=bool)
7、union1d(A,B),returns the unique set of elements in 2 arrays.相当于集合并
8、intersect1d(A,B)相当于集合中的取交
9、setdiff1d(A,B),在集合A中,不在集合B中
10、setxor1d(A,B),相当于取集合异或,只在一个集合中的元素
11、sort
a=np.random.randn(,);
print a
print np.sort(a,)
print np.sort(a,)
print np.sort(a,None) [[ 2.33262004 -2.17579511 1.02508041]
[-0.11651321 1.02673882 1.25183328]] [[-2.17579511 1.02508041 2.33262004]
[-0.11651321 1.02673882 1.25183328]] [[-0.11651321 -2.17579511 1.02508041]
[ 2.33262004 1.02673882 1.25183328]] [-2.17579511 -0.11651321 1.02508041 1.02673882 1.25183328 2.33262004]
注意:A.sort()和sort(A)之间的不同,一个会改变数据结构,一个不会。
>>> x = randn()
>>> x
array([ 2.70362768, -0.80380223, -0.10376901])
>>> sort(x)
array([-0.80380223, -0.10376901, 2.70362768])
>>> x
array([ 2.70362768, -0.80380223, -0.10376901])
>>> x.sort() # In-place, changes x
>>> x
array([-0.80380223, -0.10376901, 2.70362768])
12、max, amax, argmax, min, amin, argmin
max是数组的方法,amax是函数,argtmax返回
a=np.random.randn(,);
print a
print np.amax(a,)
print np.amax(a,)
print np.amax(a,None) [[ -1.20363617e-01 6.09840964e-01 -2.42821192e-01 -1.87136859e+00
-9.24036132e-01]
[ -2.12137767e-04 -4.49847000e-01 6.05104140e-02 5.00253683e-01
1.63359279e+00]
[ -3.41458128e-01 -9.52592527e-01 8.66845911e-01 -1.26919405e+00
1.67080515e+00]] [ 0.60984096 1.63359279 1.67080515] [ -2.12137767e-04 6.09840964e-01 8.66845911e-01 5.00253683e-01
1.67080515e+00] 1.67080515388
13、minimum(A,B), maximum(A,B)比较两个数组,返回两个数组对应位置中最小的或最大的数
introduction to python for statistics,analysis笔记3的更多相关文章
- introduction to python for statistics,analysis笔记2
一.行列式连接concatenate函数,axis=0是垂直拼接,axis=1是水平拼接 x=np.array([[],[,]]); y=np.array([[],[,]]); z=np.concat ...
- 学习笔记之Python for Data Analysis
Python for Data Analysis, 2nd Edition https://www.safaribooksonline.com/library/view/python-for-data ...
- 数据分析---《Python for Data Analysis》学习笔记【04】
<Python for Data Analysis>一书由Wes Mckinney所著,中文译名是<利用Python进行数据分析>.这里记录一下学习过程,其中有些方法和书中不同 ...
- 数据分析---《Python for Data Analysis》学习笔记【03】
<Python for Data Analysis>一书由Wes Mckinney所著,中文译名是<利用Python进行数据分析>.这里记录一下学习过程,其中有些方法和书中不同 ...
- 数据分析---《Python for Data Analysis》学习笔记【02】
<Python for Data Analysis>一书由Wes Mckinney所著,中文译名是<利用Python进行数据分析>.这里记录一下学习过程,其中有些方法和书中不同 ...
- 数据分析---《Python for Data Analysis》学习笔记【01】
<Python for Data Analysis>一书由Wes Mckinney所著,中文译名是<利用Python进行数据分析>.这里记录一下学习过程,其中有些方法和书中不同 ...
- An Introduction to Stock Market Data Analysis with R (Part 1)
Around September of 2016 I wrote two articles on using Python for accessing, visualizing, and evalua ...
- 《python for data analysis》第五章,pandas的基本使用
<利用python进行数据分析>一书的第五章源码与读书笔记 直接上代码 # -*- coding:utf-8 -*-# <python for data analysis>第五 ...
- Requests:Python HTTP Module学习笔记(一)(转)
Requests:Python HTTP Module学习笔记(一) 在学习用python写爬虫的时候用到了Requests这个Http网络库,这个库简单好用并且功能强大,完全可以代替python的标 ...
随机推荐
- MySQL 动态sql语句运行 用时间做表名
1. 描写叙述 在使用数据的时候,我时候我们须要非常多数据库,并且想用时间来做表名以区分.可是MySQL在存储过程中不支持使用变量名来做表名或者列名. 比方,有一个表我们想以"2015-07 ...
- [Node.js]28. Level 5: Express Server
Now let's create an express server which queries out for this search term and just returns the json. ...
- 1. Change the emulator screen size
1. "Windows" ==> "Android Virtual Device Manager" ==> Select one emulator ...
- 解决Windows Git Bash中文乱码问题
在git 安装目录 etc 下面 添加以下配置信息 1,/etc/gitconfig: [gui] encoding = utf-8 #代码库统一用urf-8,在git gui中可以正常显示中文 [i ...
- 【Javascript Demo】根据Email地址跳转到相应的邮箱登录页面
我的初步想法是通过指定的邮箱地址自动查找到对应的邮箱登录页面,但是用数据库.js什么的都有局限性,因为各种各样的邮箱太多了,不能都包含的到,网上找了半天都没有找到满意的答案,自己又想不出方法,只能暂时 ...
- /etc/rc.d/init.d/functions文件详细分析
/etc/rc.d/init.d/functions文件详细分析 functions这个脚本是给/etc/init.d里边的文件使用的(可理解为全局文件). 提供了一些基础的功能,看看里边究竟有些什么 ...
- ASP.NET伪静态
http://www.duote.com/tech/5/14543.html 三.伪静态的坏处 当然犹如一篇文章的作者所说的:"如果流量稍大一些使用伪静态就出现CPU使用超负荷,我的同时在线 ...
- php之表单-1
PHP 表单和用户输入 PHP 中的 $_GET 和 $_POST 变量用于检索表单中的信息,比如用户输入. PHP 表单处理 有一点很重要的事情值得注意,当处理 HTML 表单时,PHP 能把来自 ...
- JDK目录结构和文件作用介绍
要想深入了解Java必须对JDK的组成, 本文对JDK6里的目录做了基本的介绍,主要还是讲解了下JDK里的各种可执行程序或工具的用途Java(TM) 有两个平台 JRE 运行平台,包括Java虚拟机, ...
- POJ 3414 Pots(BFS+回溯)
Pots Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11705 Accepted: 4956 Special J ...