IT/Python 3

np.unravel_index() 설명 및 사용예시 정리

Function Signature numpy.unravel_index(indices, shape, order='C') shape = (M, N) 으로 주어질 때, Matrix (M, N) 내 원소는 0 부터 M * N-1 까지 존재한다고 가정 indicies = index: int (or indicies: list of int)가 위치한 좌표를 나타냄 예시1 : np.unravel_index(6, (3, 4)) shape: (3, 4) -> np.arange(12).reshape(3, 4) = 0~11 로 채워진 M = 3, N =4인 matrix 0 1 2 (return j) 3 0 0 1 2 3 1 (return i) 4 5 6 (index) 7 2 8 9 10 11 (1, 2) 예시2 : np.ar..

IT/Python 2022.11.15

python encoding

[python encoding] https://wikidocs.net/15133 인코딩(encoding) : 문자셋의 규칙대로 바이트를 만드는 방법 .py 내 default encoding 명시 : # -*- coding: utf-8 -*- (파이썬에서 사용되는 문자열은 모두 유니코드 문자열) >>> b = a.encode('utf-8') >>> b b'Life is too short' >>> type(b) 디코딩 (decoding) >>> a = '한글' >>> b = a.encode('euc-kr') >>> b.decode('euc-kr') '한글' [ Encoding with File I/O] 1) 입력으로 받은 바이트 문자열을 가능한한 가장 빨리 유니코드 문자열로 디코딩 할 것. 2) 변환된 유니..

IT/Python 2018.10.15