Numpy 편의기능 및 기본조작
np.eye(row, {col}, {band_id}, {dtype})
: band에 1 채워넣기
- 0,0 을 기준으로 대각선 항 -> band
np.identity(num, {dtype})
: identity matrix
- Same as
np.eye(3)
: 3x3 매트릭스
np.tri(row, {col}, {k=band_id}, {dtype})
: lower triangular matrix
-
nonzero entry = 1
-
a = np.eye(row, {col},{band_id}, {dtype})
-
K <= band id 의 모든 밴드에 1을 채워넣고 나머지는 0 을 채움
np.tril(a, {k=band_id})
: band_id를 포함한 lower 부분을 copy
np.triu(a, {k=band_id})
: band_id를 포함한 upper 부분을 copy
np.full((row, col), value)
: 지정된 값으로 채우기
np.randomn.rand(row, col)
- 데이터타입 지정 불가 ->
np.float64
고정 - 0과 1 사이 무작위 값으로 채워짐
np.copy(a)
: 서로 같은 메모리를 참조 : 하나가 변하면 다른 하나도 변함
np.reshape(a, vector or shape)
np.reshape(a, 6)
: 1D arraynp.reshape(a, (3, 2))
: 2D array
np.diag(a, k=band_id)
: band 추출 후 1D array로 만듦
- b is READ ONLY
- 동일 메모리 공간 참조
- 입력이 1D array (벡터)이면 square 행렬 생성
np.diagflat(M, k=band_id)
: M를 1D화 한뒤에 square matrix 생성
np.trace(a, offset=band_id)
- diagonal entry ( band entry )를 더한 값
- \(\left[\begin{matrix}\\1 & 2 & 3 \\1 & 2 & 3 \\1 & 2 & 3 \\ \end{matrix}\right]\) →
np.trace(a)
returns 15,np.trace(a, offset=-1)
returns 12
np.hstack((tuple))
: 수평으로 쌓아감 - tuple 순서대로 행(row, shape[0]) 개수가 맞아야 함
np.vstack((tuple))
: 수직으로 쌓아감 - tuple 순서대로 행(col, shape[0]) 개수가 맞아야 함
Methods
transpose()
method
- 단, 1d arr는 무변
flatten
method
-
행렬 a를 1d array 로 만들어 copy
-
Same as
np.ravel(a)
Properties
real
: 실수 부분
imag
: 허수 부분
conjegate
: copy
Matrix Multiplication
M1 @ M2
or np.matmul(M1, M2)
*** or / is not multiplication !! **
Matrix-Vector Product
M @ arr
or np.matmul(M, arr)
Inner Product
np.dot()
is …
- Real vector same as
vdot()
- complex vector : conjugate가 빠진 채로 계산