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的标 ... 
随机推荐
- Unix时间戳转换
			import time def timestamp_datetime(value): format = '%Y-%m-%d %H:%M:%S' # value为传入的值为时间戳(整 ... 
- 无障碍阅读:页面缩放兼容性处理(zoom,Firefox火狐浏览器)
			1.无障碍阅读使用场景 无障碍阅读一般在政府类网站使用比较多,如: 天津海事局(http://www.tjmsa.gov.cn/),其中天津海事局的页面放大和页面缩小在firefox浏览器下存在bug ... 
- Java 基础【12】 日期类型
			java api中日期类型的继承关系 java.lang.Object --java.util.Date --java.sql.Date --java.sql.Time --java.sql.Time ... 
- 安装 启动sshd服务:
			.先确认是否已安装ssh服务: [root@localhost ~]# rpm -qa | grep openssh-server openssh-server-.3p1-.fc12.i686 (这行 ... 
- JAR,WAR,EAR区别
			JAR WAR EAR 英文 Java Archive file Web Archive file Enterprise Archive file 包含内容 class.properties文件,是文 ... 
- Redis学习(6)-常用命令
			List命令 value值为LinkedList类型. 使用环境: 1,做大数据集合的增删. 2,任务队列.用户任务队列 链表查看 lrange key start end:获取链表从start到en ... 
- nnCron LITE
			nnCron LITE is a small, but full-featured scheduler that can start applications and open documents a ... 
- opencv在手机上实现照片背景虚化
			概述 使用androidstudio开发,在手机上实现照片背景虚化 详细 代码下载:http://www.demodashi.com/demo/10599.html 一.准备工作 1.需要下载安装an ... 
- Linux内核源代码分析方法
			Linux内核源代码分析方法 一.内核源代码之我见 Linux内核代码的庞大令不少人"望而生畏",也正由于如此,使得人们对Linux的了解仅处于泛泛的层次.假设想透析Linux ... 
- 基于docker的centos:latest镜像制作nginx的镜像
			Dockerfile和nginx.repo在同一目录下 先创建nginx.repo [root@localhost nginx]# cat nginx.repo [nginx] name=nginx ... 
