파이썬 생태계에서
과학적 계산의 기본이 되는 라이브러리
NumPy 소개 :
NumPy는 파이썬에서 과학 계산과 수치 연산을 효율적으로 처리하기 위한 라이브러리
- n-dimensional array(다차원 배열)인 ndarray 객체를 중심으로 고성능 수치 계산을 지원
- 벡터화 연산을 통해 루프 없이 대량의 데이터를 빠르게 처리할 수 있음.
- 또한, 선형대수, 통계 등 다양한 수학적 기능을 제공하여 데이터 분석, 머신러닝, 시뮬레이션 등에서 필수적인 도구로 사용됨.
- openCV, Sickit-image에서도 기본 데이터 타입으로 NumPy의 ndarray를 사용함.
CPU 기반의 Tensor (or N-dimensional Array)를 다루게 해줌:

공식 Site는 다음과 같음:
NumPy -
Use the interactive shell to try NumPy in the browser
numpy.org
다루는 기본 dtype (array의 element의 데이터 타입)에 대한 참고 자료
https://dsaint31.tistory.com/456
[Programming] Primitive Data Type : C, C++, NumPy, Torch
Primitive Data Type이(Unboxed type)란?C, C++, NumPy, Torch, TensorFlow 등에서 사용되는 numeric data type들은보통 unboxed type이라고도 불리는 primitive data type들이다.unboxed type에서는할당된 메모리 bit들이 해당 numeric
dsaint31.tistory.com
기본 사용법:
2024.09.09 - [Python] - [NumPy] 생성 및 초기화, 기본 조작 (1)
[NumPy] 생성 및 초기화, 기본 조작 (1)
1. ndarray 생성하기 (=tensor생성하기)np.array ( seq [,dtype])list 나 tuple 등의 sequence 객체로부터 ndarray 생성.dtype : data type of element.float64 : default type in the numpy. *uint8 : unsigned int (8bit), the most commonly used for im
ds31x.tistory.com
Indexing :
NumPy에서 indexing은 4+1가지 방식을 따름.
- scalar를 이용한 indexing ( simple indexing ) : array[0]
- slicing
- boolean mask : array[array > 1]
- fancy indexing : vectorized indexing. index들을 element로 가지는 array를 넘겨줌.
- combined indexing : 앞서 4가지가 조합된 indexing
simple indexing, slicing, fancy indexing, boolean mask
2024.03.18 - [Python] - [DL] Tensor: Indexing <Simple, Slicing, Fancy, Boolean Mask>
[DL] Tensor: Indexing <Simple, Slicing, Fancy, Boolean Mask>
NumPy나 PyTorch, Tensorflow의 텐서들도파이썬의 list 또는 tubple 에서의 indexing과 slicing이 거의 그대로 사용됨.2023.07.12 - [Python] - [Python] list (sequence type) : summary [Python] list (sequence type) : summarylist는 ordered m
ds31x.tistory.com
fancy indexing과 combined indexing에 대한 좀더 자세한 글! (Broadcasting 을 보고와서 읽을 것)
https://dsaint31.tistory.com/374
[NumPy] Fancy Indexing & Combined Indexing
IndexingNumPy에서 indexing은 4+1 가지 방식을 따름.scalar를 이용한 indexing ( simple indexing ) : array[0]slicingboolean mask : array[array > 1]fancy indexing : vectorized indexing. index들을 element로 가지는 array를 넘겨줌.combined
dsaint31.tistory.com
조건에 의한 indexing (Simple version)
2024.03.19 - [Python] - [ML] where: numpy 의 idx찾기
[ML] where: numpy 의 idx찾기
np.where 함수numpy에서 ndarray 인스턴스에서 특정 조건을 만족하는 elements의 위치(index, idx)를 찾는 기능을numpy 모듈의 where 함수가 제공해줌.사실 where 함수는 특정 조건에 따라 값을 바꾸어주는 기능
ds31x.tistory.com
조건에 의한 indexing (좀 더 자세히)
https://dsaint31.tistory.com/212
NumPy 검색
np.where# np.where는 NumPy의 조건 기반 선택 함수np.where(condition[, x, y]) Return elements chosen from x or y depending on condition.condition : 검색에 사용될 조건.실제로 boolean array가 됨.x : condition이 True에 해당하는 위
dsaint31.tistory.com
* np.argwhere 자료 추가할 것.
최대, 최소 값과 index구하기
2024.03.28 - [Python] - [DL] Tensor에서 maximum, minimum 찾기
[DL] Tensor에서 maximum, minimum 찾기
NumPy 의 ndarray에서np.max 와 np.min 함수를 이용하여 최대, 최소인 값을 구함.특정 축을 axis parameter로 지정하여 구할 수 있음 (결과는 해당 axis가 1이 됨.)np.argmax 와 na.argmin 함수를 이용하여 최대, 최소
ds31x.tistory.com
Broadcasting :
https://dsaint31.tistory.com/359
[NumPy] Broadcasting
0. Broadcasting이란?tensor와 scalar를 연산시킬 때 scalar를 상대 tensor와 같은 shape이면서 해당 scalar의 값을 가진 tensor로 변경시키고나서 이 scalar로부터 만들어진 tensor와 상대 tensor를 동작시키는 방식
dsaint31.tistory.com
Sorting :
https://dsaint31.tistory.com/344
[NumPy] sorting: 정렬
Numpy에서 지원하는 sorting method(or function)은Numpy의 특성상 같은 데이터타입의 array이므로,Python에서 제공하는 built-in function들보다 효율성이 높음. 관련 gisthttps://gist.github.com/dsaint31x/4126817bbc2324e7e9bc6f
dsaint31.tistory.com
https://dsaint31.tistory.com/474
[NumPy] searchsorted
np.searchsorted sort가 된 기존의 ndarray A 에 대해,입력으로 주어지는 ndarray B 의 element들의 값을 보고기존의 ndarray A 의 어느 index에 놓이게 될지를 반환한다.반환되는 ndarray의 shape는 query에 해당하는 B
dsaint31.tistory.com
축의 순서 변경 및 matrix 나누고 합치기 :
2024.03.16 - [Python] - [DL] Tensor: Transpose and Permute
[DL] Tensor: Transpose and Permute
TransposeTranspose(전치)의 linear algebra에서의 정의는 다음과 같음.Given an m x n matrix A,the transpose of A is the n x m matrix,denoted by AT whose columns are formed from the corresponding rows of A.간단하게 말하면 행과 열을 바
ds31x.tistory.com
https://dsaint31.tistory.com/208
NumPy 배열 병합 : 영상 붙이기
1. numpy.vstack numpy.vstack(tup) : Stack arrays in sequence vertically (rowwise) axis 0로 ndarray들을 붙임 2d image라면 위아래로 붙여지게 됨. Simple example import numpy as np a = np.ones((4,3)) b = np.zeros((4,3)) np.vstack( (a,b) ) Image
dsaint31.tistory.com
https://dsaint31.tistory.com/211
NumPy 배열 나누기: 영상 자르기
1. numpy.vsplit numpy.vsplit(array, indices_or_sections) : Split an array into multiple sub-arrays vertically (row-wise) axis 0 (행)로 array를 잘라 나눔. array가 image라면 수직으로 잘려진다. Simple example import numpy as np a = np.arange
dsaint31.tistory.com
Vectorized Op. and Aggregating :
2024.03.19 - [Python] - [Tensor] vectorized op. (or universal func)
[Tensor] vectorized op. (or universal func)
Numpy에서 제공하는 ufunc. (Universal Functions)은 homogeneous and contiguous tensor 에서 모든 elements에 같은 연산을 적용하여기존의 반복 loop에 기반한 연산에 비해 압도적인 속도를 보이면서 간편한 연산자
ds31x.tistory.com
https://dsaint31.tistory.com/216
NumPy : sum, mean, std, and so on
영상이나 텐서를 처리할 때, 각 pixel intensity 나 각 요소에 대해 다양한 통계처리가 필요함.NumPy는 자체적으로 다양한 통계처리 함수들 (집계함수, 또는 Aggregation Function 이라고 불림) 을 제공함. 참
dsaint31.tistory.com
2024.03.20 - [Python] - [Tensor] NaN Safe Aggregation Functions
[Tensor] NaN Safe Aggregation Functions
NaN (Not a Number) 값을 포함하는 Tensor 인스턴스에서Aggregation Function을 사용할 때,NaN을 무시 또는 특정값으로 처리하는 기능을 제공하는 함수.NumPy기존의 aggregation function의 이름에 nan을 앞에 붙인 이
ds31x.tistory.com
기타
2024.03.15 - [Python] - [DL] Tensor 간의 변환: NumPy, PyTorch, TensorFlow
[DL] Tensor 간의 변환: NumPy, PyTorch, TensorFlow
pytorch와 numpy의 경우, 텐서를 추상화하고 있는 tensor와 ndarray 를 제공하며, 이 둘은 zero-copy interoperability를 가진다고 말할 수 있을 정도로 상호호환이 가능하다. TensorFlow도 numpy와 상당히 연관되어
ds31x.tistory.com
같이보면 좋은 자료들
2023.10.06 - [분류 전체보기] - [Python] Python 정리
[Summary] Python 정리
Programming Language and Python 소개2023.10.23 - [Python] - [Python] Programming Language and Introduction of Python. [Python] Programming Language and Introduction of Python.Computer and Programhttps://dsaint31.tistory.com/436: computer 의 정의와 pr
ds31x.tistory.com
'Python' 카테고리의 다른 글
| [CV] cv2.calibrateCamera (1) | 2024.09.22 |
|---|---|
| [Etc] SW Version: Semantic Versioning + packaging.version (0) | 2024.09.19 |
| [Py] sys.exit() (1) | 2024.09.11 |
| [Py] Namespace Package (0) | 2024.09.11 |
| [CV] Chessboard관련 함수들: OpenCV (1) | 2024.09.10 |