[Math] Cartesian Product (or Descartes Product, Product Set)
·
.../Math
Cartesian Product (or Descartes Product)공집합(empty set, null set)이 아닌 여러 sets를 이용하여 새로운 set을 만드는 연산. Cartesian product는operand인 여러 집합들의각 elements를  원소(component, element)로 하는 tuple을 element(원소)로 하는 set을 반환함. 2개의 집합 $A$, $B$의 Cartesian product $A\times B$는 다음과 같음.$$A\times B= \{ (a,b) | a \in A, b\in B\}$$ $n$ 개의 집합 $A_1, A_2, \dots, A_n$의 Cartesian Product는 다음과 같이 정의됨.$$\displaystyle \prod^n_{i=1..
[NumPy] Fancy Indexing & Combined Indexing
·
Programming/DIP
IndexingNumPy에서 indexing은 4+1 가지 방식을 따름.scalar를 이용한 indexing ( simple indexing ) : array[0]slicingboolean mask : array[array > 1]fancy indexing : vectorized indexing. index들을 element로 가지는 array를 넘겨줌.combined indexing : 앞서 4가지가 조합된 indexingfancy indexing의 경우, PyTorch 에서는 Tensor-based Indexing 또는 Advanced Indexing이라고도 불림. scalar를 이용한 indexing과 slicing, boolean mask를 이용한 indexing은 다음 글을 참고: https:/..
[NumPy] Broadcasting
·
Programming/DIP
ndarray와 scalar를 연산시킬때, scalar를 상대 ndarray와 같은 shape이면서 해당 scalar의 값을 가진 ndarray로 변경시키고나서 이 scalar로부터 만들어진 ndarray와 상대 ndarray를 동작시키는 방식으로 elementwise연산이 수행되는 기능. 주의할 것은 scalar 를 확장시키는 것이 기본이라는 점임. PyTorch나 TensorFlow의 텐서도 같은 방식으로 broadcasting이 수행된다. 이를 정리하면 다음과 같은 Rule에 따른다고 생각할 수 있음. Rules of Broadcasting Rule 1 두 ndarray의 차원의 수(number of dimensions)가 같지 않을 경우, 적은 ndarray의 shape가 leading side쪽..
Vector check
·
.../Physics
Check NumPy Version import numpy as np np.__version__ 1. 다음에 언급된 Physical Quantity들이 scalar인지 vector인지 고르시오. $20 \text{m}^2$의 넓이 : scalar $10 N$의 힘 : vector 2. 다음 벡터의 L2-Norm(크기)을 구하시오 $\vec{a} = \langle1,0,2\rangle$ $\vec{b}=\langle0,3\rangle$ vec = [[1,0,2],[0,3,0]] L2_norm = np.linalg.norm(vec,axis=1,ord=2) print('2-1:',L2_norm[0],'|np.sqrt(5)',np.sqrt(5)) print('2-2:',L2_norm[1]) 3. 다음을 계산하시..
NumPy : sum, mean, std, and so on
·
Programming/DIP
영상을 처리할 때, 영상의 각 pixel intensity에 대해 다양한 통계처리가 필요함. NumPy는 자체적으로 다양한 통계처리 함수들 (집계함수, 또는 Aggregation Function 이라고 불림) 을 제공함. 참고로, 영상 데이터에서는 pixel (or element)의 값이 NaN인 경우가 거의 없으나 다른 matrix나 tensor 데이터의 경우에는 NaN 인 원소를 가질 수 있음. 이 경우, NaN Safe Aggregation Functions를 사용하여 NaN은 무시하고 값을 구할 수 있음. https://ds31x.tistory.com/223 [Tensor] NaN Safe Aggregation Functions NaN (Not a Number) 값을 포함하는 Tensor 인스턴스..
NumPy 검색
·
Programming/DIP
np.wherenumpy.where(condition[, x, y]) :Return elements chosen from x or y depending on condition.condition : 검색에 사용될 조건.x : condition이 True에 해당하는 위치에 지정되는 값 또는 array (검색에 사용된 ndarray로 broadcast처리 가능한 shape이어야 함)y : condition이 False에 해당하는 위치에 지정되는 값 또는 array (검색에 사용된 ndarray로 broadcast처리 가능한 shape이어야 함)반환값x,y를 설정해준 경우엔 조건에 따라 해당 값으로 채워진 ndarray임.아닌 경우, condition에 True에 해당하는 위치의 idx. ndim 2인 ndar..