Python Pandas की समीक्षा · Python Pandas (एक नज़र) •Data क analysis क § का एक ऄत्ं हत्वर्ण हहस्सा हा
Python+numpy pandas 1편
-
Upload
yong-joon-moon -
Category
Software
-
view
683 -
download
13
Transcript of Python+numpy pandas 1편
![Page 1: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/1.jpg)
1
Moon Yong Joon
Python numpy,pandas기초 -1 편
![Page 2: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/2.jpg)
2
1. Numpy 기초2.Numpy dtype 클래스
3. Numpy 함수4. 선형대수 기초
![Page 3: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/3.jpg)
3
1. Numpy 기초
![Page 4: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/4.jpg)
4
NdArray 이해
![Page 5: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/5.jpg)
5
NDARRAY CLASS
![Page 6: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/6.jpg)
6
Ndarray 와 list 는 내부 구조부터 다르게 되어있어 ndarray 가 더 처리가 빠르게 실행됨
ndarray vs. list 구조
![Page 7: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/7.jpg)
7
Ndarray 는 데이터를 관리하고 data-type 은 실제 데이터들의 값을 관리하며 , array scalar 는 위치를 관리
ndarray 구조
![Page 8: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/8.jpg)
8
ndarray 는 각 원소별로 동일한 데이터 타입으로 처리
데이터 타입 부여
원소 원소 원소array( [ ], dtype )
, ,
![Page 9: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/9.jpg)
9
numpy.array 생성시 단일값 (scalar value) 를 넣으면 arrary 타입이 아니 일반 타입을 만듬
0 차원
[0,0]Row : 행
Column: 열
![Page 10: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/10.jpg)
10
배열의 특징 . 차원 , 형태 , 요소를 가지고 있음생성시 데이터와 타입을 넣으면 ndim( 차원 ) 으로 확인
1 차원
[0,0] [0,1] [0,2]Row : 행
Column: 열0
0 1 2
![Page 11: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/11.jpg)
11
3 행 , 3 열의 배열을 기준으로 어떻게 내부를 행과 열로 처리하는 지를 이해
2 차원 배열
[0,0] [0,1] [0,2]
[1,0] [1,1] [1,2]
[2,0] [2,1] [2,2]
Row : 행
Column: 열0
1
2
0 1 2
Index 접근 표기법 배열명 [ 행 ][ 열 ]배열명 [ 행 , 열 ]Slice 접근 표기법 배열명 [ 슬라이스 , 슬라이스 ]
![Page 12: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/12.jpg)
12
numpy.array 생성시 sequence 각 요소에 대해 접근변수와 타입을 정할 수 있음
3 차원
![Page 13: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/13.jpg)
13
Ndarray 타입을 검색이나 슬라이싱은 참조만 할당하므로 변경을 반지하기 위해서는 새로운 ndarray 로 만들어 사용 . copy 메소드가 필요
할당은 참조만 전달
![Page 14: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/14.jpg)
14
F ( 화씨 ) = c( 섭씨 ) * 9 / 5 + 32 이 공식을 기준으로 연속적인 배열을 loop 문 없이 계산
벡터화 연산 : for 문 미사용
ndarray 특징은 array 원소 만큼 자동으로 순환 계산해서 ndarray 로 반환함
![Page 15: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/15.jpg)
15
list 와 ndarray 계산 성능numpy.ndarray 로 계산시 python list 타입에 비해 계산 속도가 빠름
배열을 c 언어처럼 관리하므로 별도의 in-dex 를 구성하지 않으므로 계산속도 빠름
![Page 16: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/16.jpg)
16
NDARRAY 속성
![Page 17: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/17.jpg)
17
Ndarray 생성시 shape, dtype,strides 이 인스턴스 속성이 생성됨
ndarray 생성 : 주요 변수 1
변수 Description
ndarray.ndim ndarray 객체에 대한 차원
ndarray.shape ndarray 객체에 대한 다차원 모습ndarray.size ndarray 객체에 대한 원소의 갯수
ndarray.dtype ndarray 객체에 대한 원소 타입ndarray.itemsize ndarray 객체에 대한 원소의 사이즈
ndarray.data ndarray 객체에 데이터는 itemsize 크기의 hex 값으로 표현
![Page 18: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/18.jpg)
18
일차원과 다차원의 원소 개수를 len() 함수로 처리시 다른 결과가 나옴
ndarray 생성 : 주요 변수 2
변수 Description
ndarray.real ndarray 에 생성된 복소수에서 실수값
ndarray.imag ndarray 에 생성된 복소수에서 허수값
ndarray.strides ndarray 객체에 대한 원소의 크기
ndarray.base ndarray 객체에 다른 곳에 할당할 경우 그 원천에 대한 것을 가지고 있음
ndarray.flat ndarray 객체가 차원을 가질 경우 하나로 연계해서 index 로 처리
ndarray.T ndarray 객체에 대한 역핼력
![Page 19: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/19.jpg)
19
함수와 메소드가 이중 지원
![Page 20: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/20.jpg)
20
numpy 모듈에 함수 , ndarray 내의 메소드가 이중으로 지원하는 함수와 메소드가 많지만 용도에 맞춰사용 -> 메소드 사용을 권고
함수와 메소드 지원
numpy module
함수ndarray class
메소드
![Page 21: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/21.jpg)
21
python 은 외부 함수를 클래스 내부 변수에 할당하면 메소드로 인식하므로 함수와 메소드를 동일하게 처리가 가능한 구조임
함수와 메소드를 동일하게 처리
![Page 22: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/22.jpg)
22
copy(obj, order='K') , obj.copy(order=‘C’)는거의 동일한 처리함order 는 {'C', 'F', 'A', 'K'}. 'C' : C-order, 'F' : Fortran-order, 'A' : fortran 이면 F, 아니면 C 처리 , 'K' : obj 에 매치해서 처리
numpy.copy vs ndarray.copy
![Page 23: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/23.jpg)
23
NDARRAY
![Page 24: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/24.jpg)
24
numpy 내의 데이터 타입은 array 함수와 ndarray 생성자로 생성
ndarray 생성하기
![Page 25: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/25.jpg)
25
ndarray 생성하면 내부 원소들은 float 타입으로 생성됨
ndarray 데이터 변경
![Page 26: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/26.jpg)
26
Ndarray 생성 함수 이해하기
![Page 27: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/27.jpg)
27
ONES
![Page 28: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/28.jpg)
28
ndarray 생성하면 내부 원소들은 one 원소를 가지는 ndarray 를 생성
ones 함수
1 차원
2 차원
3 차원
![Page 29: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/29.jpg)
29
ZEROS
![Page 30: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/30.jpg)
30
ndarray 생성하면 내부 원소들은 zero 원소를 가지는 ndarray 를 생성
zeros 함수
1 차원
2 차원
3 차원
![Page 31: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/31.jpg)
31
ndarray 생성하면 내부 원소들은 (int,float) 원소를 가지는 ndarray 를 생성
zeros 함수 : 원소를 튜플로 생성
![Page 32: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/32.jpg)
32
EMPTY
![Page 33: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/33.jpg)
33
numpy.empty 는 shape 를 넣고 array 생성numpy.empty 생성
empty(shape, dtype=float, order='C')
row-major (C-style)or column-major (Fortran-style) order in memory.
![Page 34: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/34.jpg)
34
ONES/ZEROS/EMPTY LIKES
![Page 35: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/35.jpg)
35
기존 생성된 배열을 기반으로 ones, zeros, empty 로 객체를 생성할 경우 사용
ones,zeros,empty likes
![Page 36: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/36.jpg)
36
EYE
![Page 37: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/37.jpg)
37
numpy.eye 생성시 숫자를 정의하면 정방행렬을 만들고 대각선이 1 로 세팅 . 단 k 값을 줄 경우 위치를 바꿈
numpy.eye 생성 예시
K=0 K=1 K=2
K=-1
K=-2
numpy.eye(n, m=None, k=0, dtype=<type 'float'>)
![Page 38: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/38.jpg)
38
IDENTITY
![Page 39: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/39.jpg)
39
numpy.identiry 함수로 생성하면 실제 정방형 ndarray 타입이 생기고 대각선으로는 1 이 정의됨
numpy.identity 생성함수
numpy.identity(n, dtype=None)
![Page 40: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/40.jpg)
40
LINSPACE
![Page 41: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/41.jpg)
41
이 함수로 시작과 종료 그리고 num( 요소의 개수 )로 생성
numpy.linspace 생성함수
linspace(start, stop, num=50, endpoint=True, retstep=False)
![Page 42: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/42.jpg)
42
Linspace 로 endpoint 를 false 로 하면 최종 값은 포함하지 않음
linspace : 최종값 포함 유무
![Page 43: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/43.jpg)
43
ARANGE
![Page 44: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/44.jpg)
44
리스트와 ndarray 타입의 차이는 배열객체 안의 메소드들이 계산에 대한 차이가 반영
range 와 numpy.arange 비교
numpy.arange 는 다양한 타입으로 ar-ray 를 생성할 수 있음
arange([start,] stop[, step,], dtype=None)
![Page 45: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/45.jpg)
45
ASARRAY
![Page 46: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/46.jpg)
46
List 등을 ndarray 타입으로 전환하는 함수asarray
asarray(array_likes, dtype=None, order=None)
![Page 47: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/47.jpg)
47
Numpy 검색 / 갱신 하기
![Page 48: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/48.jpg)
48
내부 원소 접근 방식
![Page 49: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/49.jpg)
49
numpy.ndarray 타입에서는 __getitem__ 에 논리연산 등 다양한 처리를 허용
__getitem__ 비교
![Page 50: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/50.jpg)
50
Index 와 slice 처리시 기존 리스트의 방식보다 더 다양한 처리를 위해 __setitem__ 메소드를 over-ride 함
__setitem__
![Page 51: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/51.jpg)
51
2 차원 : 행과 열 접근
![Page 52: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/52.jpg)
52
배열명 [ 행 범위 , 열 범위 ] 행으로 접근 , 열로 접근
배열 접근하기 : 행과 열구분
[0,0] [0,1] [0,2]
[1,0] [1,1] [1,2]
[2,0] [2,1] [2,2]
Row : 행
Column: 열
0
1
2
0 1 2
[0,0] [0,1] [0,2]
[1,0] [1,1] [1,2]
[2,0] [2,1] [2,2]
Row : 행
Column: 열
0
1
2
0 1 2
첫번째 행 접근
첫번째 열 접근
![Page 53: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/53.jpg)
53
첫번째와 두번째 행과 두번째와 세번째 열로 접근배열 접근하기 : 행렬로 구분
[0,0] [0,1] [0,2]
[1,0] [1,1] [1,2]
[2,0] [2,1] [2,2]
Row : 행
Column: 열
0
1
2
0 1 2
![Page 54: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/54.jpg)
54
행과 열의 인덱스를 지정하면 실제 값에 접근해서 보여줌
배열 접근하기 : 값
[0,0] [0,1] [0,2]
[1,0] [1,1] [1,2]
[2,0] [2,1] [2,2]
Row : 행
Column: 열
0
1
2
0 1 2
![Page 55: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/55.jpg)
55
배열계산시 scalar 값과 계산시 크기가 작은 것을 동일한 크기로 계산되도록 확산이 발생
배열 값 바꾸기 : Broadcasting
npl[2:5] 는 원소가 3 개에 스칼라 값인 42 를 할당했지만[42,42,42] 로 인식하여 처리
![Page 56: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/56.jpg)
56
N 차원 배열 처리
![Page 57: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/57.jpg)
57
7*4 배열을 정의하고 첫번째 열의 값을 99 으로 변경
다차원 배열 : 열 조회 / 변경
배열명 [ 행접근 , 열접근 ]
Slicing 도 행접근과 열접근으로 별도로 할 수 있음배열명 [ 행 슬라이싱 , 열 슬라이싱 ] 으로 배열을 접근 가능
![Page 58: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/58.jpg)
58
비교연산 처리
![Page 59: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/59.jpg)
59
ndarray 와 ndarray 간의 비교연산 . Scala 값은 broadcasting 하므로 ndarray 동일 모형의 동일값으로 인지해서 처리된 후 bool 값을 가지는 ndarray 가 생성됨
ndarray 와 비교연산 처리
ndarray 비교연산 ndarrayndarray = 배열명 [ 논리연산 ]
논리 연산 등 다양한 연산을 이용해서 배열 접근
![Page 60: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/60.jpg)
60
[f > 2.0] 조건의 원소가 True 인 것만을 조회 1 차원 배열 : 조회
![Page 61: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/61.jpg)
61
[f > 0.5] 조건의 원소가 True 인 것만을 조회 다차원 배열 : 조회
![Page 62: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/62.jpg)
62
[data1 <0] = 99 실제 배열의 원소들 값이 0보다 작을 경우 99 으로 전환
다차원 배열 : 변경
![Page 63: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/63.jpg)
63
Numpy Fancy Indexing이해하기
![Page 64: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/64.jpg)
64
원소추출
![Page 65: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/65.jpg)
65
정수배열을 사용한 색인 ( 양수 , 음수를 이용 ) 이며 행에 대한 정보를 list 로 제공해서 3 번째와 1 번째를 출력
행 검색
정방향 역방향
![Page 66: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/66.jpg)
66
두개의 배열을 주면 첫번째 배열은 행 , 두번째 배열은 열로 순서쌍을 구성해서 값을 추출
순서쌍 처리후 원소만 추출
![Page 67: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/67.jpg)
67
배열추출
![Page 68: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/68.jpg)
68
첫번째 배열은 행을 처리 두번째 배열은 열을 처리해서 행과열로 구성된 배열 추출
행과 열로 구성된 배열 추출
np.ix_ 함수를 이용
![Page 69: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/69.jpg)
69
표현식 사용
![Page 70: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/70.jpg)
70
배열에 직적 비교연산 수식을 제공해서 원소 추출표현식 : 비교 연산
![Page 71: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/71.jpg)
71
배열의 각 원소가 3 으로 나누었을때 나머지가 0 이 아닌 경우 원소 추출
표현식 : 산출 + 비교 연산
![Page 72: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/72.jpg)
72
배열 내의 원소가 nonzero 인 것을 식별하기 위해 nonzero 메소드 사용
메소드 사용
![Page 73: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/73.jpg)
73
Matrix class
![Page 74: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/74.jpg)
74
NDARRAY 와 MATRIX 구분
![Page 75: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/75.jpg)
75
다차원 배열을 생성하지만 matrix 는 MATLAB 기능을 지원
ndarray 와 matrix 구분
구분 ndarray matrix
차원 다차원 가능 2 차원* 연산자 요소간 곱 행렬곱
numpy.multiply() 요소간 곱 요소간 곱numpy.dot() 행렬곱 행렬곱
![Page 76: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/76.jpg)
76
Matrix 는 dot/* 처리가 동일 , ndarry 는 */multiply 가 동일
ndarray 와 matrix 연산 비교
![Page 77: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/77.jpg)
77
MATRIX 덧셈 / 뺄셈
![Page 78: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/78.jpg)
78
행렬 덧셈은 A 열과 B 의 행과 열이 같으면 덧셈과 뺄셈을 처리
Matrix 덧셈 / 뺄셈
![Page 79: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/79.jpg)
79
Matrix 에 대한 곱셈과 나눗셈도 각 원소별로 처리Matrix 곱셈 / 나눗셈
![Page 80: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/80.jpg)
80
MATRIX DOT
![Page 81: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/81.jpg)
81
행렬 곱셈은 A 열과 B 의 행이 같으면 A 행과 B의 열로 계산처리 됨
Matrix dot
A(m*k) B(k*n) C(m*n)
. =
![Page 82: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/82.jpg)
82
행렬 (2 행 2 열 ) 과 행렬 (2 행 2 열 ) 을 곱하면 결과는 2 행 2 열의 행렬로 처리하고 ndarray타입으로 리턴
Dot 연산 : ndarray
![Page 83: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/83.jpg)
83
ndarray 를 행렬 연산하고 (4,1) 배열로 만들고 100 으로 나눠서 결과값 출력
Dot 연산 : ndarray (4,3)*(3,1)
![Page 84: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/84.jpg)
84
Dot 함수 호출과 동일하게 처리됨
Matrix 타입 : 연산 (*) 은 dot연산
![Page 85: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/85.jpg)
85
Matrix 타입과 ndarray 간의 연산을 할 경우 ndarray 타입을 matrix 타입으로 전환 후 연산처리
Matrix 연산 (*) : asmatrix
![Page 86: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/86.jpg)
86
2. Numpy Dtype class
![Page 87: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/87.jpg)
87
dtype class 이해하기
![Page 88: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/88.jpg)
88
메모리 처리 방식
![Page 89: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/89.jpg)
89
(<: little-endian, >: big-endian, |: not-relevant),
Byte 메모리 저장방식
.
<: little-endian
>: big-endian
|: not-relevant
리틀 엔디안은 최하위 비트 (LSB) 부터 부호화되어 저장된다 . 예를 들면 , 숫자 12 는 2 진수로 나타내면 1100 인데 리틀 엔디안은 0011 로 각각 저장된다 .
이 방식은 데이터의 최상위 비트가 가장 높은 주소에 저장되므로 그냥 보기에는 역으로 보인다 . 빅 엔디안은 최상위 비트 (MSB) 부터 부호화되어 저장되며 예를 들면 , 숫자 12 는 2 진수로 나타내면 1100 인데 빅 엔디안은 1100 으로 저장된다 .
문자를 저장할 때 사용 endian 가 상관없이 처리
![Page 90: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/90.jpg)
90
itemsize 메소드는 저장되는 메모리의 크기이며 lit-tle-endian 은 좌측 , big-endian 은 우측부터 저장
Little-endian/big-endian
.
![Page 91: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/91.jpg)
91
endian 에 상관없이 문자를 저장할때 제일 왼쪽부터 저장됨
not-relevant
.
![Page 92: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/92.jpg)
92
데이터 타입 이해하기
![Page 93: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/93.jpg)
93
(<: little-endian, >: big-endian, |: not-relevant)와 연계처리하여 데이터 타입 지정
array-protocol type string
기본 타입 설명‘t’ Bit field'b' boolean'i' (signed) integer'u' unsigned integer'f' floating-point'c' complex-floating point'O' (Python) objects
'S', 'a' (byte-)string'U' Unicode'V' raw data (void)
.
![Page 94: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/94.jpg)
94
타입 매칭Ndarray 타입과 매칭 1
Ndarray 타입 타입 코드 설명int8, uint8 i1,u1 1byites 정수형
int16, uint16 i2,u2 2byites 정수형int32, uint32 i4,u4 4byites 정수형int64, uint64 i8,u8 8byites 정수형
float16 f2 반정밀도 부동소수점float32 f4, f 단정밀도 부동소수점 . C 언어의 float 형 호환float64 f8, d 배정밀도 부동소수점 , C 언어의 double, Python 의
float 객체float128 f16, g 확장 정밀도 부동소수점
complex64 c8 32 비트 부동소수점 2 개를 가지는 복소수complex128 c16 64 비트 부동소수점 2 개를 가지는 복소수
.
![Page 95: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/95.jpg)
95
타입 매칭Ndarray 타입과 매칭 2
Ndarray 타입 타입 코드 설명complex256 c32 128 비트 부동소수점 2 개를 가지는 복소수
bool ? True, False 값을 저장하는 불리언 형object O 파이썬 객체형string_ S 고정길이 문자열형 - 각 글자는 1 바이트
unicode_ U 고정길이 유니코드
.
![Page 96: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/96.jpg)
96
비교연산 결과가 bool 타입 , float 타입을 astype 메소드로 타입을 전환
bool-> int, float->int 로 전환
![Page 97: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/97.jpg)
97
numpy 내의 데이터 타입은 ndarray 생성자로 사용
Int/float/ bool_ 생성
![Page 98: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/98.jpg)
98
NUMPY.DTYPE
![Page 99: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/99.jpg)
99
numpy.dtype 은 ndarray 를 생성에 필요한 데이터 타입을 정의하기 위한 클래스
numpy.dtype 생성자
numpy.dtype(object, align=False, copy=False)
![Page 100: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/100.jpg)
100
Array 원소가 하나의 타입만 세팅할 수도 있고 , 여러 개의 데이터 타입을 구성할 수 있음
numpy.dtype 생성 예시
Structured type : two fieldStructured type : one field
![Page 101: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/101.jpg)
101
NUMPY.DTYPE 변수
![Page 102: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/102.jpg)
102
dtype 변수 - 1
Method Description
char타입 표시
itemsize 타입내의 요소들이 구성 크기name 현재 타입명names Ordered list field 명 . 없으면 None
shape 원소들에 대한 모형 크기
num Builtin 타입이 순서
![Page 103: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/103.jpg)
103
dtype 변수 - 2
Method Description type numpy 내의 타입으로 표시str Array-protocol 타입스트링 표시
<: little-endian 으로 float 8 개 bytes 처리
isbuiltin 0:structure array type1: numpy 내부 타입2: 사용자 정의 타입
byteorder = : 기본< : little> : big| : not applicable
alignment 타입내의 요소들이 구성 크기isalignedstruct ?
![Page 104: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/104.jpg)
104
dtype 변수 - 3
Method Descriptiondescr Array interface 표시
hasobject any reference-counted objects in any fields or sub-dtypes 가 존재시 True
subdtype Tuple (item_dtype, shape) if this dtype describes a sub-array, and None otherwise.
base 기본 정의된 타입
kind array-protocol type
isnative 파이썬 내부 byte order 사용여부
![Page 105: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/105.jpg)
105
dtype 변수 - 4
Method Descriptionflags Interpret 되어진 bit flags
fields Dtype 정의한 필드들
metadata ?
![Page 106: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/106.jpg)
106
dtype class 칼럼 이름 부여하기
![Page 107: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/107.jpg)
107
DTYPE 구조
![Page 108: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/108.jpg)
108
칼럼별 처리를 위해 index 이외의 이름을 부여하여 직접 접근하여 처리
ndarray 내부 원소에 이름 부여
‘x’ ‘y’ ‘z’
array[‘x’] 로 접근하면 ‘ x’ 칼럼에 대해 전부 접근 가능
![Page 109: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/109.jpg)
109
dtype 정의시 칼럼명 , 칼럼값을 튜플로 정의하면 칼럼을 명으로 조회가 가능
dtype 에 칼럼명 정의 : tuple
![Page 110: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/110.jpg)
110
dtype 내의 dict 내 에 names 에 칼럼명 정의 , formats 에 타입정의 또는 칼럼명과 타입으로 정의해서 사용가능
dtype 에 칼럼명 정의 : dict
![Page 111: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/111.jpg)
111
ndarray 생성하면 내부를 (int, float) 를 원소로 한 2 차원 배열이 생성됨
dtype 에 칼럼명 정의 : 배열처리
![Page 112: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/112.jpg)
112
dtype 내의 names 변수로 칼럼 필드를 조회 및 갱신이 가능
칼럼 필드명 변경
![Page 113: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/113.jpg)
113
칼럼명으로 접근 / 변경
![Page 114: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/114.jpg)
114
numpy.array 생성시 sequence 각 요소에 대해 접근변수와 타입을 정할 수 있음
칼럼명 접근
해당 이름에 해당되는 위치의 모든 값을 ndarray 타입으로 출력
인덱스를 찾고 내부의 이름으로 검색
![Page 115: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/115.jpg)
115
numpy.array 를 여러 칼럼단위로 접근시는 실제 칼럼명을 내부에 리스트에 넣어서 검색
칼럼명 접근 : fancy
![Page 116: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/116.jpg)
116
numpy.array 생성시 sequence 각 요소에 대해 접근변수에 대한 값을 변경할 있음
칼럼명으로 변경
![Page 117: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/117.jpg)
117
Numpy axis 이해하기
![Page 118: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/118.jpg)
118
배열 축 이해 : 2 차원
![Page 119: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/119.jpg)
119
Axis 는 배열의 축을 나타내며 0 은 열이고 , 1 은 행을 표시
axis 이해하기 : 2 차원
[0,0] [0,1] [0,2]
[1,0] [1,1] [1,2]Row : 행
Column: 열
0
1
2
0 1 2
![Page 120: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/120.jpg)
120
데이터를 복사하지 않고 데이터 모양이 바뀐 뷰를 반환하는 기능
배열 전치
![Page 121: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/121.jpg)
121
배열 축 이해 : 3 차원
![Page 122: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/122.jpg)
122
Axis 는 배열의 축을 0 은 두개의 행렬에서 각 열원소별로 , 1 은 행끼리 처리 , 2 은 내부 원소끼리 처리
axis 이해하기 : 3 차원
4 5
6 7Row : 행
Column: 열
0
1
0 1
0 1
2 3Row : 행
Column: 열
0
1
0 1
![Page 123: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/123.jpg)
123
Tuple 로 축번호를 받아 치환하지만 axis 는 0,1이 default 이므로 배열전치를 하려면 1,0 으로 축을 변경해야 함
축변경 : transpose
3 차원인 경우
![Page 124: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/124.jpg)
124
3. Numpy 함수
![Page 125: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/125.jpg)
125
Numpy 함수
![Page 126: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/126.jpg)
126
INNER/OUTER 함수 이해하기
![Page 127: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/127.jpg)
127
A = [[a1,b1] B = [[a2,b2]]numpy.inner(A,B) array([[a1*a2 + b1*b2]])[[1*4+0*1]]
inner 계산 방식
1 0 4 11 0
4 1
4=.
![Page 128: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/128.jpg)
128
벡터의 내부 곱한 것을 더해서 값을 표현Inner 예시
![Page 129: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/129.jpg)
129
A = [[a1,b1]] B = [[a2,b2]]numpy.outer(A,B) array([[a1*a2 , a1*b2][ b1*a2, b1*b2]]) [[1*4,1*1] [0*4+0*1]]
outer
1 0 4 1 1
0
4 1
4 1
0 0
=
![Page 130: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/130.jpg)
130
벡터의 내부 곱한 것을 더해서 값을 표현첫번째 벡터의 전치와 두번째 벡터와의 Dot 연산과 같은 결과
outer 예시
![Page 131: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/131.jpg)
131
숫자처리 함수
![Page 132: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/132.jpg)
132
abs, fabs : 각 원소의 절대값을 구함 . 복소수가 아닌 경우에는 fabs 로 빠른 연산을 처리 sign: 부호에 대한 처리 , 1 은 양수 , -1 은 음수
절대값 / 부호 처리
![Page 133: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/133.jpg)
133
exp 는 지수 계산log,log10,log2,log1p 는 자연로그 , 로그 10, 로그2, 로그 (1+x)
지수와 로그
![Page 134: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/134.jpg)
134
square 는 거듭제곱 , sqrt 는 제곱근 , power 는 두 배열의 거듭제곱
거듭제곱 / 제곱근
![Page 135: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/135.jpg)
135
ceil : 각 원소의 값보다 같거나 큰 정수 중 가장 큰 정수를 반환 floor : 각 원소의 값보다 작거나 같은 정수 중 가장 작은수 반환 rint : 각 원소의 소수자리를 반올림하고 dtype 유지
절사 /절상
![Page 136: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/136.jpg)
136
add, subtract, multiply, divide, floor_divide 처리
사칙연산
![Page 137: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/137.jpg)
137
modf : 단항연산으로 자신의 나머지와 몫 구하기 mod : 이항연산으로 나머지만 구함
Mod 연산
![Page 138: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/138.jpg)
138
두 배열간의 관계를 표시하거나 부울 표시된 결과에 대해 any/all 로 전체 결과를 확인
관계연산
![Page 139: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/139.jpg)
139
where 연산은 조건을 표현한 배열을 기준으로 True 일 경우 첫번째 배열의 요소 , False 일 경우는 두번째 배열의 요소로 처리
where 연산
![Page 140: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/140.jpg)
140
sqrt(a2 + b2) 을 처리하는 함수 hypot 함수
![Page 141: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/141.jpg)
141
집합 함수
![Page 142: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/142.jpg)
142
집합처럼 만드는 unique 함수와 포함관계를 표시하는 in1d 함수
unique/in1d
![Page 143: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/143.jpg)
143
집합연산은 일단 1 차원적으로 변환해서 합집합 , 교집합 , 차집합 , 대칭차집합처리
집합연산하기
![Page 144: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/144.jpg)
144
통계 함수
![Page 145: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/145.jpg)
145
통계 기본 함수 제공하며 cumsum/cumprod는 각 원소의 값을 누적하는 함수
합 /평균 / 분산 / 표준편차
![Page 146: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/146.jpg)
146
값이 최대값 / 최소값를 구하거나 값의 최대값과 최소값의 인덱스를 구함
최대값 / 최소값
![Page 147: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/147.jpg)
147
SHAPE 조정 함수
![Page 148: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/148.jpg)
148
Flatten 메소드는 하나의 별도의 새로운 객체를 만들기 위해 copy 연산을 사용하지만 ravel 은 view 만 제공하므로 갱신하면 기존 ndarray 가 변경
Flatten/ravel 메소드의 차이 :
![Page 149: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/149.jpg)
149
다차원에서 flat 으로 처리시 order 로 c언어타입과 fortran 언어타입으로 표현 가능
Flatten/ravel 메소드 : order
![Page 150: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/150.jpg)
150
reshape(a, newshape, order='C') 는 a 는 array-like, newshape 는 int, tuple, order 는 'C', 'F', 'A‘ 로 처리
reshape 함수
![Page 151: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/151.jpg)
151
concatenate((a1, a2, ...), axis=0) 로 array를 연결
concatenate 함수 : 1 차원
![Page 152: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/152.jpg)
152
concatenate((a1, a2, ...), axis=0) 로 array를 연결
concatenate 함수 : n 차원
![Page 153: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/153.jpg)
153
np.newaxis 변수는 slice 처리와 같이 사용해서 축을 바꿈 1 행 배열은 1 열 배열로 2 행 3 열 배열은 3 행 2 열 배열로 변환
np.newaxis 변수
![Page 154: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/154.jpg)
154
A 배열에 대한 Reps 는 axis 축에 따른 반복을 표시numpy.tile(A, reps)
tile
x = np.array([ [1, 2], [3, 4]]) np.tile(x, (3,4))
1. Reps 가 스칼라 값은 배수만큼 증가2. Reps 가 벡터값 일 경우 행과 열에 따라 추가
![Page 155: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/155.jpg)
155
Tile 함수를 이용해서 array_like 를 모형에 따라ndarray 로 변환
Array_like 를 ndarray 로 변환
![Page 156: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/156.jpg)
156
row_stack 함수는 row 단위로 통합하고 col-umn_stack 함수는 column 단위로 통합
row/column stack 함수 : 1
![Page 157: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/157.jpg)
157
Column_stack 은 행은 그대로이고 열이 추가Row_stack 은 열은 그대로이고 행의 추가
row/column stack 함수 : 2
![Page 158: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/158.jpg)
158
count_nonzero 함수를 이용해서 개수 확인 및 flatnonzero 함수를 이용해서 인덱스를 식별
nonzero 확인 함수
![Page 159: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/159.jpg)
159
FILE 처리 함수
![Page 160: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/160.jpg)
160
생성된 ndarray 를 파일에 저장 ( 확장자 : nd)했다가 다시 load 해서 처리가 가능
save/load : 파일 처리
![Page 161: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/161.jpg)
161
numpy.random array 생성하기
![Page 162: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/162.jpg)
162
주요 생성 함수
![Page 163: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/163.jpg)
163
rand(균등분포 ) 에 따라 ndarray 를 생성 모양이 없을 경우는 scalar 값을 생성
rand : uniform distribution
![Page 164: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/164.jpg)
164
randn( 정규분포 ) 에 따라 ndarray 를 생성 모양이 없을 경우는 scalar 값을 생성
randn : "standard normal"distribution
![Page 165: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/165.jpg)
165
randint(low, high=None, size=None) 는 최저값 , 최고값 -1, 총 길이 인자를 넣어 ndarray 로 리턴Size 에 tuple 로 선언시 다차원 생성
randint
![Page 166: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/166.jpg)
166
random_sample(size=None) 에 size 가 없을 경우는 하나의 값만 생성하고 size 를 주면 ndar-ray 를 생성
random_sample
![Page 167: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/167.jpg)
167
ranf(size=None) 에 size 가 없을 경우는 하나의 값만 생성하고 size 를 주면 ndarray 를 생성
ranf
![Page 168: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/168.jpg)
168
random(size=None) 에 size 가 없을 경우는 하나의 값만 생성하고 size 를 주면 ndarray 를 생성
random
![Page 169: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/169.jpg)
169
RANDOM GENERATOR
![Page 170: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/170.jpg)
170
size 를 argument 로 취하는데 기본값은 None이다 . 만약 size 가 None 이라면 , 하나의 값이 생성되고 반환된다 . 만약 size 가 정수라면 , 1-D 행렬이 랜덤변수들로 채워져 반환된다 .
RandomState : 생성
![Page 171: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/171.jpg)
171
Seed 는 반복 가능한 것을 처리할 때 사용하면 get-state() 로 처리하면 현재 상태가 출력
RandomState :seed/get_state
![Page 172: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/172.jpg)
172
seed 는 반복적인 random 을 동일한 범주에서 처리하기 위한 방식으로 random 변수를 고정시킴
seed
![Page 173: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/173.jpg)
173
DISTRIBUTIONS
![Page 174: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/174.jpg)
174
n 은 trial , p 는 구간 [0,1] 에 성공 P 는 확률 이항 분포에서 작성한 것임
Binomial : 이항분포
![Page 175: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/175.jpg)
175
[low, high) 는 low 를 포함하지만 high 를 포함하지 않는 정규분로를 표시
Uniform
![Page 176: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/176.jpg)
176
a standard Normal distribution (mean=0, stdev=1) 표시
standard_normal
![Page 177: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/177.jpg)
177
주요 순서처리 함수
![Page 178: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/178.jpg)
178
순열의 값인 원소로 선택된 배열의 원소를 섞기 permutation
![Page 179: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/179.jpg)
179
choice(a, size=None, replace=True, p=None)A 값을 int, size 는 모형 , p 는 나오는 원소에 대한 확률을 정의
choice : int
![Page 180: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/180.jpg)
180
choice(a, size=None, replace=True, p=None)a 값을 array, size 는 모형 ,replace=False 는 사이즈 변경 불가 , p 는 나오는 원소에 대한 확률을 정의
choice : replace 속성
![Page 181: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/181.jpg)
181
선택된 배열의 원소를 섞기shuffle
![Page 182: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/182.jpg)
182
4. 선형대수 기초
![Page 183: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/183.jpg)
183
차원 이해
![Page 184: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/184.jpg)
184
차원이해
![Page 185: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/185.jpg)
185
차원 (次元 ) 은 수학에서 공간 내에 있는 점 등의 위치를 나타내기 위해 필요한 축의 개수를 말함
기하 차원
![Page 186: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/186.jpg)
186
Tensor 는 n 차원 array 를 표시 , 1 차원은 벡터 , 2차원은 matrix, 3 차원은 cube, 4 차원은 cube 의 , vector, 5 차원은 cube 의 matrix, 6 차원은 cube 의 cube
tensor 차원
![Page 187: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/187.jpg)
187
Vector 이해
![Page 188: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/188.jpg)
188
벡터란
![Page 189: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/189.jpg)
189
스칼라는 number, vector 는 숫자들의 list(row or column), matrix 는 숫자들의 array( rows, columns) 그리고 vector 는 Matrix
스칼라 / 벡터 / 행렬
벡터는 tail 부터 head까지의 유향선분으로 표시
![Page 190: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/190.jpg)
190
벡터는 방향과 크기로 특징 지어지는 물리량을 나타내면 벡터의 길이는 크기와 방향을 표시
vector
![Page 191: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/191.jpg)
191
ndarray 는 벡터 1xN, Nx1, 그리고 N 크기의 1 차원 배열이 모두 각각 다르며 , 벡터는 그 자체로 특정 좌표를 나타내기도 하지만 방향을 나타냄
배열과 vertor 구분
scalar 배열 vector
양 , 정적 위치 양 , 정적 위치 변위 , 속도 , 힘 (방향성 )
1 차원 N 차원 N 차원단순 값 행 , 열 구분 없음 행벡터 , 열벡터
![Page 192: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/192.jpg)
192
스칼라 / 벡터 / 행렬스칼라 / 벡터 / 행렬 예시
![Page 193: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/193.jpg)
193
VECTOR 크기
![Page 194: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/194.jpg)
194
벡터의 크기는 ||v|| = sqrt(v0^2 + v1^2 + v2^2... + vn^2) 로 표현
벡터 크기
벡터 b = (6,8) 의 크기|b| = √( 62 + 82 ) = √( 36+64 ) = √100 = 10
![Page 195: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/195.jpg)
195
벡터의 길이 즉 크기를 구함 vector 크기
![Page 196: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/196.jpg)
196
벡터의 크기 (Magnitude) 는 원소들의 제곱을 더하고 이에 대한 제곱근의 값벡터의 크기는 x축의 변위와 y축의 변위를 이용하여 피타고라스 정리
Vector 크기 계산
![Page 197: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/197.jpg)
197
단위벡터 (unit vector) 는 크기가 1 인 벡터단위벡터
크기가 1 인 벡터
표기법은 문자에 모자 (hat) 을 사용해서 표시
모든 벡터는 단위벡터에 대해 sclae 배수 만큼의 크기를 가진 벡터
![Page 198: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/198.jpg)
198
해당 벡터를 0 ~ 1 의 값으로 정규화단위벡터 정규화
![Page 199: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/199.jpg)
199
스칼라와 연산
![Page 200: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/200.jpg)
200
Ndarray 에 대한 수치 계산은 기본 벡터화해서 배열을 만들어서 계산함
수치계산
+ : 배열간 덧셈- : 배열간 뺄셈 * : 배열간 곱셈
/ : 배열간 나눗셈** : 배열간 제곱
% : 배열간 나머지
![Page 201: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/201.jpg)
201
multiply 함수는 1 차원 ndarray 에서는 *연산자와 같은 계산 결과가 나옴
multiply 함수 : 곱셈
![Page 202: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/202.jpg)
202
The vector (8,13) and the vector (26,7) add up to the vector (34,20)Example: add the vectors a = (8,13) and b = (26,7)c = a + bc = (8,13) + (26,7) = (8+26,13+7) = (34,20)
벡터 : +
a
b
a
b
c
![Page 203: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/203.jpg)
203
두 벡터 평행 이동해 평행사변형을 만든 후 가운데 벡터가 실제 덧셈한 벡터를 표시
Vector 연산 : +
e
d
fe
d
![Page 204: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/204.jpg)
204
벡터의 방향성을 반대로 이동한 실제 벡터를 처리벡터 : -
Example: subtract k = (4,5) from v = (12,2)a = v + −ka = (12,2) + −(4,5) = (12,2) + (−4,−5) = (12−4,2−5) = (8,−3)
e
d g
-e
-e
![Page 205: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/205.jpg)
205
벡터의 각 원소에 스칼라값만큼 곱하여 표시벡터 : 스칼라곱
벡터 m = [7,3]
A = 3m= [21,9]
![Page 206: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/206.jpg)
206
벡터의 합
![Page 207: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/207.jpg)
207
두 벡터를 더하면 평형사변형의 대각선인 새 벡터가 생성
vector 의 합
![Page 208: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/208.jpg)
208
내적과 외적 비교
![Page 209: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/209.jpg)
209
내적 vs 외적구분 내적 외적
명칭 Inner product, dot product, scalar product
Outer product, vector product, cross product
표기 .(Dot) X(cross)
대상 벡터 n 차원 3 차원
공식 a1 b1 + a2 b2 + …. + an bn
(a2 b3 – a3 b2, a3 b1 – a1 b3, a1 b2 – a2
b1)
|a||b| cos 각도 |a||b| sin 각도 n
결과 scalar vector
![Page 210: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/210.jpg)
210
내적 (Inner Product) 산식은 두벡터의 크기에 cos 각을 곱한 결과 또는 두벡터간의 원소들이 곱의 합산과 같은 결과
내적 산식
a · b = |a| × |b| × cos(θ)
Where:|a| : vector a 크기|b| : vector b 크기
θ : a and b 사이의 각
a · b = ax × bx + ay × by
![Page 211: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/211.jpg)
211
두벡터에 내적 연산에 대한 수학적 처리 예시내적 수학적 예시 : 2 차원
a · b = |a| × |b| × cos(θ)a · b = 10 × 13 × cos(59.5°)a · b = 10 × 13 × 0.5075...a · b = 65.98... = 66 (rounded)
a · b = ax × bx + ay × by
a · b = -6 × 5 + 8 × 12a · b = -30 + 96a · b = 66
![Page 212: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/212.jpg)
212
Dot 연산을 통한 계산3 차원 내적 예시 1
a · b = ax × bx + ay × by + az × bz
a · b = 9 × 4 + 2 × 8 + 7 × 10a · b = 36 + 16 + 70a · b = 122
![Page 213: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/213.jpg)
213
두벡터 사이의 각 구하기3 차원 내적 예시 2
a 벡터의 크기 |a| = √(42 + 82 + 102) = √(16 + 64 + 100) = √180b 벡터의 크기 |b| = √(92 + 22 + 72) = √(81 + 4 + 49) = √134내적 구하기 a · b = 9*4+ 2*8+ 7*10 = 36+16+70 = 122
각 구하기a · b = |a| × |b| × cos(θ) 산식에 대입122 = √180 × √134 × cos(θ)cos(θ) = 122 / (√180 × √134)cos(θ) = 0.7855...θ = cos-1(0.7855...) = 38.2...°
![Page 214: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/214.jpg)
214
벡터 a 와 b 의 외적은 a × b 로 정의된다 .외적의 결과로 나온 벡터 c 는 벡터 a 와 b 의 수직인 벡터로 오른손 법칙의 방향
외적
Vector productCross product
![Page 215: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/215.jpg)
215
벡터의 원소간의 cross 적을 처리 외적 산식 : 2 차원
v = [a1,a2] u = [b1,b2]
a1 a2
b1 b2
a1*b2 – a2*b1 Example: The cross product of a = (2,3) and b = (5,6)c = a1b2 − a2b1 = 2×6− 3×5 = −3
Answer: a × b = -3
![Page 216: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/216.jpg)
216
벡터의 원소간의 cross 적을 처리 외적 산식 : 3 차원
v = [a1,a2,a3] u = [b1,b2,b3]
a2 a3 a1 a2 b2 b3 b1 b2
x 측 : a2*b3 – a3*b2y 측 : a3*b1 – a1*b2
z 측 : a1*b2 – a2*b1
Example: The cross product of a = (2,3,4) and b = (5,6,7)cx = aybz − azby = 3×7 − 4×6 = −3cy = azbx − axbz = 4×5 − 2×7 = 6cz = axby − aybx = 2×6 − 3×5 = −3Answer: a × b = (−3,6,−3)
![Page 217: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/217.jpg)
217
DOT
![Page 218: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/218.jpg)
218
두 벡터의 스칼라 또는 inner product 는 길이와 코사인 사이의 최소 각도의 곱입니다 . 결과는 스칼라입니다 . 벡터 사이에 dot product 이기도 함 .
Scalar product
![Page 219: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/219.jpg)
219
1 차원 배열간의 dot 연산은 각 원소의 곱이 합산으로 표시
vector dot 연산
![Page 220: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/220.jpg)
220
두벡터에 대한 내적 (dot) 연산은 같은 위치의 원소를 곱해서 합산함두벡터의 곱셈은 단순히 원소를 곱해서 벡터를 유지
내적 (dot)
![Page 221: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/221.jpg)
221
CROSS
![Page 222: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/222.jpg)
222
두 벡터의 벡터 곱은 새로운 벡터를 생성 , 이 벡터의 축은 두 원본 벡터의 평면에 수직이며 , 그 방향은 오른쪽 규칙에 의해 결정
Vector product
![Page 223: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/223.jpg)
223
벡터곱 (vector 곱 , 영어 : cross product) 또는 외적 (外積 ) 은 수학에서 3 차원 공간의 벡터들간의 이항연산의 일종이다 . 연산의 결과가 스칼라인 스칼라곱과는 달리 연산의 결과가 벡터
vector 곱셈
a = [0,0,1] b = [0,1,0]
a*b = [0-1,0-0,0-0] = [-1,0,0]
주요 산식 :a*b = (a2b3−a3b2, a3b1−a1b3, a1b2−a2b1)
![Page 224: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/224.jpg)
224
벡터곱 연산을 np.cross 함수를 이용하여 처리cross 연산 : 1 차원
![Page 225: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/225.jpg)
225
두벡터에 대한 외적 (cross) 연산은 다른 위치의 원소를 곱해서 뺄셈2 차원 벡터는 스칼라 값으로 나옴 3 차원 벡터이상 표시 됨
외적 산식
![Page 226: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/226.jpg)
226
TRIPLE PRODUCT
![Page 227: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/227.jpg)
227
The triple product of three vectors is a combination of a vector product and a scalar product
triple product
![Page 228: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/228.jpg)
228
행렬 이해하기
![Page 229: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/229.jpg)
229
행렬이란
![Page 230: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/230.jpg)
230
행렬매트릭스라고도 하는데 행렬의 가로 줄을 행 , 세로 줄을 열로 표시함
![Page 231: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/231.jpg)
231
DIAGONAL MATRIX
![Page 232: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/232.jpg)
232
대각행렬 : diag
정사각행렬 A= (aij)(i, j= 1, 2, 3,…, n) 의 원소 aij 가 aij=0(i≠j) 을 만족시키는 행렬A 의 주대각선 위에 있는 원소 ( 대각선원소 ) aij(i=j) 외의 원소 aij(i≠j) 가 모두 0 인 행렬
![Page 233: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/233.jpg)
233
IDENTITY MATRIX
![Page 234: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/234.jpg)
234
항등행렬 : identity
모든 행렬과 dot 연산시 자기 자신이 나오게 하는 단위행렬
![Page 235: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/235.jpg)
235
TRIANGULAR MATRIX
![Page 236: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/236.jpg)
236
삼각행렬 : tril/triu
상삼각 행렬 (Upper triangular matrix)과 하삼각 행렬 (lower triangular matrix) 을 총칭하여 일컫는 말 .
Upper triangular matrix
lower triangular matrix
![Page 237: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/237.jpg)
237
행렬 산술연산
![Page 238: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/238.jpg)
238
행렬 산술연산두 행렬의 원소별로 산술연산 (+/-/*) 처리
+-*/
=
+-*/
+-*/
+-*/
+-*/
+-*/
+-*/
1 2 34 5 6
1 2 34 5 6+ = 1+1 2+2 3+3
4+4 5+5 6+6
= 2 4 68 10 12
![Page 239: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/239.jpg)
239
행렬 산술연산 예시행렬에 대한 산술연식은 각 원소별로 +/-/* 처리
![Page 240: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/240.jpg)
240
행렬 전치 : T
전치 : 행렬의 행과 열을 서로 바꾸는 것 .수학책에서는 위첨자 T 로 행렬 A 의 전치를 나타낸다 .
121110987654321
A
129631185210741
TA
![Page 241: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/241.jpg)
241
DOT 연산
![Page 242: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/242.jpg)
242
dot 처리 기준 1*p, p*1
두 행렬 A 와 B 의 행렬곱셈은 행렬 A 의 각 행과 행렬 B 의 각 열끼리 곱해서 표시
AB (𝑎1𝑏1𝑎2𝑏2…𝑎𝑝𝑏𝑝) paaa 21A
pb
bb
2
1
B
1 행 *p열 P 행 1 열 1 행 1 열
![Page 243: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/243.jpg)
243
dot 처리 기준두 행렬 A 와 B 의 행렬곱셈은 행렬 A 의 각 행과 행렬 B 의 각 열끼리 곱해서 표시
pnpjpp
inijii
nj
nj
mpmjmm
ipijii
pj
pj
bbbb
bbbb
bbbbbbbb
aaaa
aaaa
aaaaaaaa
21
21
222221
111211
21
21
222221
111211
AB
pm np
nm
2 3
3 3
![Page 244: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/244.jpg)
244
A = [[a1,b1],[c1,d1]] B = [[a2,b2],[c2,d2]] numpy.-dot(A,B) array([[a1*a2 + b1*c2, a1*b2 + b1*d2], [c1*a2 + d1*c2, c1*b2 + d1*d2]) [[1*4+ 0*2, 1*1+0*2],[0*4+1*2, 0*1+1*2]]
dot : 2 차원
1 0
0 1
4 1
2 21 0
0 1
4 1
2 2
4 1
2 2
=.
![Page 245: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/245.jpg)
245
Dot 와 inner 함수는 계산시 축 기준이 차이가 있어 실제 계산된 값이 다름
dot vs inner 차이점 (2차원이상 )
dot inner
행과 열로 계산 행과 행으로 계산
행벡터와 열벡터 간의 원소를 곱한후 덧셈
행벡터와 행벡터간의 원소를 곱한후에 덧셈
N*M 과 M*N 즉 , 첫번째 열과 두번째 행이 동일
N*M 과 N*M 에 마지만 차원이 같은 경우
N*M . M*N 은 결과가 N*N N*M 과 N*M 은 결과가 N*N
![Page 246: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/246.jpg)
246
CROSS PRODUCT
![Page 247: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/247.jpg)
247
A = [[a1,b1],[c1,d1]] B = [[a2,b2],[c2,d2]] numpy.cross(A,B) = A.T * Barray([[a1*b2 - c1*a2 , b1*d2 – d1*c2])[[1*1- 0*4,0*2-1*2]]
cross 계산 방식
1 0
0 1
4 2
1 21 -2=
![Page 248: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/248.jpg)
248
n*m 행렬 일 경우 2 차원으로 표시Cross 행렬
![Page 249: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/249.jpg)
249
INNER 연산
![Page 250: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/250.jpg)
250
A = [[a1,b1],[c1,d1]] B = [[a2,b2],[c2,d2]] numpy.inner(A,B) array([[a1*a2 + b1*b2, a1*c2 + b1*d2], [c1*a2 + d1*b2, c1*c2 + d1*d2])[[1*4+0*1,1*2+0*2],[0*4+1*1, 0*2+1*2]]
inner 계산 방식
1 0
0 1
4 1
2 21 0
0 1
4 1
2 2
4 2
1 2
=.
![Page 251: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/251.jpg)
251
Inner 예시 : 2 차원 a(2,2) 행렬과 b(2,2) 행렬의 마지막 차수가 같으므로 계산결과는 out.shape = a.shape[:-1] + b.shape[:-1]
![Page 252: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/252.jpg)
252
Inner 예시 : 3 차원 a(2,3,2) 행렬과 b(2,2) 행렬의 마지막 차수가 같으므로 계산결과는 out.shape = a.shape[:-1] + b.shape[:-1]
![Page 253: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/253.jpg)
253
OUTER PRODUCT
![Page 254: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/254.jpg)
254
두개의 벡터를 가지고 벡터 크기를 행과 열로 만드는 함수1 차원이 이상일 경우 1 차원으로 만든 후에 행렬로 만듬
outer
1 0 4 1 1
0
4 1
4 1
0 0
=
2 2 2*2
![Page 255: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/255.jpg)
255
Out 는 두개의 벡터에 대한 행렬로 구성out[i, j] = a[i] * b[j]
outer: 1
![Page 256: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/256.jpg)
256
첫번째 벡터가 행이되고 두번째 벡터가 열이 되어 5*5 행렬을 만듬
outer: 2
![Page 257: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/257.jpg)
257
벡터의 값이 문자일 경우 문자 배수만큼 처리outer: 3
![Page 258: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/258.jpg)
258
대각행렬의 합
![Page 259: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/259.jpg)
259
3 차원 (2,2,2) 대각행렬의 합은 첫번째 차원의 1과 두번째의 마지막을 합산해서 출력
Trace : 3 차원 행렬
0
2
1
3
4
6
5
7
0 1
![Page 260: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/260.jpg)
260
행렬식과 역행렬 이해하기
![Page 261: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/261.jpg)
261
행렬식
![Page 262: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/262.jpg)
262
정방행렬에 하나의 수를 대응시킴으로써 , - 연립방정식의 해를 구하거나 , - 연립방정식 해의 존재성을 살피려고 할 때 쓰여짐
행렬식 (det)
3 12 2det = 3*2 – 1*2
= 4
![Page 263: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/263.jpg)
263
행렬식을 계산시 앞에 두 열을 뒤에 복사 후 계산행렬식 (det) : 3 차원
![Page 264: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/264.jpg)
264
MINOR DETERMINANT
![Page 265: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/265.jpg)
265
i 번째 행 ,j 번째 열을 제거한 부분행렬의 행렬식 : Mij
소행렬식 2 차원
2 11 2
M11 2
M12
M21
-1
-1
2
1
1
부호 +
부호 –부호 –부호 +M22 22
![Page 266: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/266.jpg)
266
i 번째 행 ,j 번째 열을 제거한 부분행렬의 행렬식 : Mij
소행렬식 3 차원
3 1 3 2 2 3 1 1 1
M11 2*1 -3*1 -1
M12
M13
2*1 -3*1 -1
2*1 -2*1 0
2 3 1 1
2 3 1 1
2 2 1 1
= 3M11+(-1)* 1M12 + 3M13 = -3+1+0 = -2
부호 +
부호 –부호 +
![Page 267: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/267.jpg)
267
소행렬식 예시 소행렬식을 구해서 행렬식 값 비교
![Page 268: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/268.jpg)
268
여인수 행렬
![Page 269: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/269.jpg)
269
소행렬식을 이용한 값을 여인수를 표시 여인수 (cofactor)
3 1 3 2 2 3 1 1 1
소행렬식 부호 결과값m11 2 3
1 1 2-3 -1 + -1
m12 2 31 1 2-3 -1 - 1
m13 2 21 1 2-2 0 + 0
m21 1 31 1 1-3 -2 - 2
m22 3 31 1 3-3 0 + 0
m23 3 11 1 3-1 2 - -2
m31 1 32 3 3-6 -3 + -3
m32 3 32 3 9-6 3 - -3
m33 3 12 2 6-2 4 + 4
![Page 270: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/270.jpg)
270
소행렬식으로 계산된 원소 즉 여인수로 구성된 행렬의 전치행렬을 수반행렬이라 함
수반행렬 (adj) 과 여인수행렬
-1 2 -3 1 0 -3 0 -2 4
-1 1 0 2 0 -2-3 -3 4
T 여인수행렬의 전치
수반행렬
![Page 271: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/271.jpg)
271
역행렬
![Page 272: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/272.jpg)
272
역행렬은 수반행렬에 행렬식으로 나눗값이 됨역행렬 (inv) – 2 차원
[[ 0.66666667 -0.33333333] [-0.33333333 0.66666667]]
1/3 * 2 -1-1 2
역행렬2 11 2
-1
A −1 = 1/det(A) * C T
![Page 273: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/273.jpg)
273
역행렬은 수반행렬에 행렬식으로 나눗값이 됨역행렬 (inv) – 3 차원
[[ 0.5 -1. 1.5] [-0.5 0. 1.5] [ 0. 1. -2. ]]
- 0.5 * -1 2 -3 1 0 -3 0 -2 4
역행렬3 1 3 2 2 3 1 1 1
-1
A −1 = 1/det(A) * C T
![Page 274: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/274.jpg)
274
역행렬 (inv) 예시 역행렬 계산
![Page 275: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/275.jpg)
275
tensor dot 이해하기
![Page 276: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/276.jpg)
276
TENSORDOT
![Page 277: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/277.jpg)
277
Tensordot 함수에 axes 를 0 으로 줄 경우 tensor product 을 연산
tensordot
![Page 278: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/278.jpg)
278
Tensordot 함수에 axes 를 0 으로 줄 경우 tensor product 을 연산
tensordot
=1 0
0 1
4 1
2 2
1 0
0 1
4 1
2 2
4 1
2 2
4 1
2 2
4 1
2 2
=
4 2
1 2
0 0
0 0
0 0
0 0
4 2
1 2
2,2 2,2 2,2,2,2
![Page 279: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/279.jpg)
279
2 차원 행렬 2 개가 만나 4 차원 행렬 구성tensordot: 예시 1
![Page 280: Python+numpy pandas 1편](https://reader031.fdocument.pub/reader031/viewer/2022020920/5871f2b51a28ab5c348b5daf/html5/thumbnails/280.jpg)
280
axes = 0 tensor product, axes = 1 ten-sor dot product, axes = 2 tenser double contraction 즉 벡터연산
tensordot: 예시 2