[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
0. Broadcasting이란?tensor와 scalar를 연산시킬 때 scalar를 상대 tensor와 같은 shape이면서 해당 scalar의 값을 가진 tensor로 변경시키고나서 이 scalar로부터 만들어진 tensor와 상대 tensor를 동작시키는 방식으로 elementwise연산이 수행되는 기능. 주의할 것은 scalar 를 확장시키는 것이 기본이라는 점임.  참고로 broadcasting은 scalar와 tensor간의 연산을 확장하여 차원이 다른 tensor간의 연산에도 사용된다:단, scalar에서 출발하므로 size가 1인 축(=scalar)을 추가하는 padding을 이용함. PyTorch나 TensorFlow의 텐서도 NumPy와 같은 방식으로 broadcasting이 수행된다..
[NumPy] sorting: 정렬
·
Programming
Numpy에서 지원하는 sorting method(or function)은Numpy의 특성상 같은 데이터타입의 array이므로,Python에서 제공하는 built-in function들보다 효율성이 높음. 관련 gisthttps://gist.github.com/dsaint31x/4126817bbc2324e7e9bc6fb49b6ed44f np_sorting.ipynbnp_sorting.ipynb. GitHub Gist: instantly share code, notes, and snippets.gist.github.comcopy based sorting컴퓨팅 자원이 충분하다면, 개인적으로 아래와 같이 copy를 반환하는 게 가장 편하다.import numpy as np x = np.array([3,4,1..
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 FunctionsNaN (Not a Number) 값을 포함하는 Tensor 인..