introduction to python for statistics,analysis笔记2
一、行列式连接concatenate函数,axis=0是垂直拼接,axis=1是水平拼接
x=np.array([[1.0,],[,]]);
y=np.array([[5.0,],[,]]);
z=np.concatenate((x,y),axis=);
print x,'\n\n'
print y,'\n\n' print z
[[ . .]
[ . .]] [[ . .]
[ . .]] [[ . .]
[ . .]
[ . .]
[ . .]]
另一种方法有:
z = vstack((x,y)) # Same as z = concatenate((x,y),axis = 0)
z = hstack((x,y)) # Same as z = concatenate((x,y),axis = 1)
二、行列式选取可能降维
>>> x = array([[1.0,2],[3,4]])
>>> x[:1,:] # Row 1, all columns, 2-dimensional
array([[ 1., 2.]])
>>> x[0,:] # Row 1, all columns, dimension reduced
array([ 1., 2.])
2、查看行列式的维数使用,np.ndim(A)函数
3、重复扩展,相当于在方括号内元素扩展
>>> x = array([[0.0]*3]*3) # *3 repeats the list 3 times
>>> x
array([[0, 0, 0],
[0, 0, 0],
[0, 0, 0]])
4、修改行列式元素值时,需要注意类型。可能会被修改,numpy中,会自动将插入的数据类型修改为行列式类型
>>> x = [, , , , ] # Integers
>>> y = array(x)
>>> y.dtype
dtype(’int32’)
>>> y[] = 3.141592
>>> y
array([, , , , ])
5、行列式的转置和重改维度大小
B=A.T#行列式转置
B=np.reshape(A,(m,n)),#m,n是要更后改的行数和列数
6、flat切片,他将行列式转换成一维行列式,进行切片
a=np.arange();
b=np.reshape(a,(,));
b.flat[:]
array([, , , , ])
7、行列式复制三种方法(1)copy()
import copy as cp
a=np.arange(10);
b=np.reshape(a,(2,5));
x1=cp.deepcopy(b[0]);#函数法
x2=b[:,0].copy();#方法
x3=np.array(b[0]);#array行列式
print b
print b[0];
print x1
print x2
print x3,'\n\n\n'
x1[0]=12;
print b
print b[0];
print x1
print x2
print x3,'\n\n\n'
x2[0]=20;
print b
print b[0];
print x1
print x2
print x3,'\n\n\n'
x3[0]=50
x2[0]=20;
print b
print b[0];
print x1
print x2
print x3,'\n\n\n'
[[0 1 2 3 4]
[5 6 7 8 9]]
[0 1 2 3 4]
[0 1 2 3 4]
[0 5]
[0 1 2 3 4] [[0 1 2 3 4]
[5 6 7 8 9]]
[0 1 2 3 4]
[12 1 2 3 4]
[0 5]
[0 1 2 3 4] [[0 1 2 3 4]
[5 6 7 8 9]]
[0 1 2 3 4]
[12 1 2 3 4]
[20 5]
[0 1 2 3 4] [[0 1 2 3 4]
[5 6 7 8 9]]
[0 1 2 3 4]
[12 1 2 3 4]
[20 5]
[50 1 2 3 4]
8、导入模块
import pylab as pl
import scipy as sp
import numpy as np
9、数组运算
(1)加减运算都符合线性代数运算
(2)乘运算要注意数组的广播机制,还不太理解???????????
一般的:数组运算是元素与元素相乘,矩阵相乘是符合线性代数运算机制的
想要改变数组的运算机制符合线性代数运算机制可以通过函数np.dot(A,B)
x=np.ones((,));
y=np.ones((,));
print np.dot(x,y) [[ . .]
[ . .]]
(3)除运算,数组和矩阵都是元素与元素之间的运算。
x=np.ones((,))*;
y=np.ones((,))*;
x/y array([[ ., ., ., .],
[ ., ., ., .]])
x=np.mat(np.ones((,))*)
y=np.mat(np.ones((,))*)
x/y matrix([[ ., ., ., .],
[ ., ., ., .]])
(4)指数运算
对于数组是元素的指数运算
x=np.array([,,]);
x** array([, , ])
对于矩阵是Z=A**m,是矩阵A碟乘m次,对于m在python中必须是整数,可以是负数,如果是负数,则Z=inv(A**(abs(m)));
x=np.mat(np.reshape(np.arange(),(,)))
print x
x** [[ ]
[ ]
[ ]] matrix([[ , , ],
[ , , ],
[ , , ]])
(5)矩阵转置运算A.transpose(),transpose(A),A.T都表示矩阵A的转置
x=np.mat(np.random.randn(,))
print x;
x.T*x [[-1.02490428 1.76366191]
[ 0.48344916 -0.36091476]] matrix([[ 1.28415188, -1.98206858],
[-1.98206858, 3.2407628 ]])
10、数组切片的不同
当使用切片或标量进行赋值时,不会复制内容。而是产生一个视图。当使用索引或逻辑值进行赋值时,会对原始数组进行复制。
a=np.arange();
b=a[:];
c = a[[,,,]]
print a
print b
b[]=;
print a
print b
print c
[ ]
[ ]
[ ]
[ ]
[ ]
introduction to python for statistics,analysis笔记2的更多相关文章
- introduction to python for statistics,analysis笔记3
一.产生数组和矩阵 1.linspace(start,end,number),产生在start和end数之间number个数 >>> x = linspace(, , ) >& ...
- 学习笔记之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的标 ...
随机推荐
- 体绘制(Volume Rendering)概述之3:光线投射算法(Ray Casting)原理和注意要点(强烈推荐呀,讲的很好)
转自:http://blog.csdn.net/liu_lin_xm/article/details/4850609 摘抄“GPU Programming And Cg Language Primer ...
- const char * 转换为char*
可以用const_cast const char* aa = "this is a const string."; char* bb = const_cast< ...
- C# ftp ListFilesOnServer
public static bool ListFilesOnServer(Uri serverUri) { // The serverUri should start with the ftp:// ...
- [Node.js] Load balancing a Http server
Let's see how to do load balancing in Node.js. Before we start with the solution, you can do a test ...
- LINUX设备驱动程序笔记(五)中断处理
<一> 中断处理流程例如以下: 1.发生中断时,CPU运行异常向量vector_irq的代码. 2.在vector_irq里面.终于会调用中断处理的总入口函数asm_do_IRQ ...
- 王立平-- android:layout_weight
效果: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMzQyNTUyNw==/font/5a6L5L2T/fontsize/400/fill/I0 ...
- 成员函数的const究竟修饰的是谁
demo <pre name="code" class="cpp">class Test { public: const void OpVar(in ...
- android 如何连真机测试
1. 设置android手机为USB调试模式.步骤: menu---> 设置 ---> 应用程序 ---> 开发 , 选择[USB调试] 2. 用USB连接手机和电脑,并确保成功.步 ...
- Hessian整合Spring
含实例源码博客推荐:http://blog.csdn.net/julyness/article/details/49023581 简介: Hessian是一个简单的连接Web服务的二进制协议. 客户端 ...
- 启动mysql出现1067错误
0. 打开mysql\bin\my.ini,查找[mysqld],在[mysqld]下面添加一行文字,skip-grant-tables 即组成 [mysqld] skip-grant-tables[ ...