파이썬+numpy+선형대수 기초+이해하기 20160519

202
PYTHON NUMPY 선선선선 Moon Yong Joon 1

Upload: yong-joon-moon

Post on 06-Jan-2017

3.186 views

Category:

Software


9 download

TRANSCRIPT

PowerPoint

Python numpy Moon Yong Joon1

Numpy Moon Yong Joon2

ndarray matrix 3

ndarray matrix matrix MATLAB ndarraymatrix 2 * numpy.multiply() numpy.dot()

4

vector : ndarray Array vector

5

ndarray matrix Matrix dot/* , ndarry */multiply

6

ndarray class7

ndarray vs. list Ndarray list ndarray 8

ndarray Ndarray data-type , array scalar 9

ndarray array( [], dtype ),,10

0numpy.array (scalar value) arrary 11[0,0]Row : Column:

1 . , , ndim() 12[0,0][0,1][0,2]Row : Column: 0012

2 3, 3 [0,0][0,1][0,2][1,0][1,1][1,2][2,0][2,1][2,2]Row : Column: 012012Index [][][, ]Slice [, ]13

3numpy.array sequence 14

Ndarray ndarray . copy 15

: for F () = c() * 9 / 5 + 32 loop

ndarray array ndarray 16

17

list ndarray numpy.ndarray python list 18

c index

Ndarray 19

ndarray : 1Ndarray shape, dtype,strides 20Descriptionndarray.ndim ndarray ndarray.shape ndarray ndarray.size ndarray ndarray.dtype ndarray ndarray.itemsize ndarray ndarray.data ndarray itemsize hex

ndarray : 2 len() 21Descriptionndarray.real ndarray ndarray.imag ndarray ndarray.strides ndarray ndarray.base ndarray ndarray.flat ndarray index ndarray.T ndarray

22

__getitem__ numpy.ndarray __getitem__

23

__setitem__ Index slice __setitem__ override

24

2 : 25

: [ , ] , [0,0][0,1][0,2][1,0][1,1][1,2][2,0][2,1][2,2]Row : Column: 012012[0,0][0,1][0,2][1,0][1,1][1,2][2,0][2,1][2,2]Row : Column: 012012

26

: [0,0][0,1][0,2][1,0][1,1][1,2][2,0][2,1][2,2]Row : Column: 012012

27

:

[0,0][0,1][0,2][1,0][1,1][1,2][2,0][2,1][2,2]Row : Column: 01201228

: Broadcasting scalar npl[2:5] 3 42 [42,42,42]

29

N 30

: / 7*4 99

[, ]

Slicing

[ , ] 31

32

ndarray ndarray ndarray . Scala broadcasting ndarray bool ndarray ndarrayndarrayndarray=33 []

1 : [f > 2.0] True 34

: [f > 0.5] True 35

: [data1 = 1-D.linalg.matrix_power(M,n)Raise a square matrix to the (integer) powern.cross(a, b, axisa=-1, axisb=-1, axisc=-1, axis=None) einsum(subscripts,*operands[,out,dtype,...])Evaluates the Einstein summation convention on the operands.kron(a,b)Kronecker product of two arrays.

194

Decompositions195

linalg.cholesky(a)Cholesky decomposition.linalg.qr(a[,mode])Compute the qr factorization of a matrix.linalg.svd(a[,full_matrices,compute_uv])Singular Value Decomposition.

196

Matrix eigenvalues197

linalg.eig(a)Compute the eigenvalues and right eigenvectors of a square array.linalg.eigh(a[,UPLO])Return the eigenvalues and eigenvectors of a Hermitian or symmetric matrix.linalg.eigvals(a)Compute the eigenvalues of a general matrix.linalg.eigvalsh(a[,UPLO])Compute the eigenvalues of a Hermitian or real symmetric matrix.linalg.eig(a)Compute the eigenvalues and right eigenvectors of a square array.

198

Norms and other numbers199

linalg.norm(x[,ord,axis,keepdims])Matrix or vector norm.linalg.cond(x[,p])Compute the condition number of a matrix.linalg.det(a)Compute the determinant of an array.linalg.matrix_rank(M[,tol])Return matrix rank of array using SVD method Rank of the array is the number of SVD singular values of the array that are greater thantol.linalg.slogdet(a)Compute the sign and (natural) logarithm of the determinant of an array.trace(a[,offset,axis1,axis2,dtype,out])Return the sum along diagonals of the array.

200

Solving equations and inverting matrices201

linalg.solve(a,b)Solve a linear matrix equation, or system of linear scalar equations.linalg.tensorsolve(a,b[,axes])Solve the tensor equationax=bfor x.linalg.lstsq(a,b[,rcond])Return the least-squares solution to a linear matrix equation.linalg.inv(a)Compute the (multiplicative) inverse of a matrix.linalg.pinv(a[,rcond])Compute the (Moore-Penrose) pseudo-inverse of a matrix.linalg.tensorinv(a[,ind])Compute the inverse of an N-dimensional array.

202