본문 바로가기
728x90
반응형

numpy12

[ML] where: numpy 의 idx찾기 np.where 함수numpy에서 ndarray 인스턴스에서 특정 조건을 만족하는 elements의 위치(index, idx)를 찾는 기능을numpy 모듈의 where 함수가 제공해줌.사실 where 함수는 특정 조건에 따라 값을 바꾸어주는 기능도 있음.다음 글 참조: 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.ti.. 2024. 3. 19.
[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 mutable collection으로, collection을 위한 python data type들 중 가장 많이 사용된다. C에서의 array와 같이 가장 기본적인 collection임. 단, heterogeneous item을 가질 수 있으며, 여러 methods를 가지는ds31x.tistory.com 단, multi-dimension에서 squ.. 2024. 3. 18.
[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.간단하게 말하면 행과 열을 바꾸는 처리이다. Tensor의 경우rank가 2 보다 클 수 있으며 해당 rank의 수만큼 축이 있다.때문에Tensor에서의 transpose는 여러 축들 중 2개를 서로의 위치를 바꾸는 것이라고 보면 된다. 주의할 것은numpy와 pytorch의 경우, aixs(축)만 변경된 것이지, 여전히 같은 데이터 (the same underlying .. 2024. 3. 16.
[DL] Tensor 객체의 attributes: ndim, shape, dtype Tensor를 추상화하는 Class들Python에서Tensor 를 추상화하는 대표적인 class는 다음과 같음.NumPy의 ndarray: numpy.arrayPyTorch의 torch.Tensor : torch.tensor()로 생성.Tensorflow의 tf.Tensor : tf.constant(), tf.convert_to_tensor(), tf.Variable 등으로 생성.https://dsaint31.tistory.com/891 [ML] Tensor: Scalar, Vector, Matrix.Tensor 종류1. Scalar (0차원 tensor)하나의 숫자로 표현되는 가장 기본적인 형태.크기(magnitude)만을 가지며 방향은 없음.예시: 온도(25°C), 나이(20), 가격(1000원)# .. 2024. 3. 15.
[DL] Tensor: dtype 변경(casting) 및 shape 변경. Tensor를 추상화하고 있는 class로는numpy.array: numpy의 ndarraytorch.tensortensorflow.constant: (or tensorflow.Variable)이 있음. 이들은 Python의 sequence types과 달리 일반적으로 다음과 같은 특징을 지님.데이터들이 연속적으로 할당되는 특징의 c,c++의 array와 매우 유사함.element들이 homogeneous인 특징을 가짐 (같은 크기의 unboxed object로 구성=같은 type들)dtyep 변경dtype는 The data type of element 를 가르키며, tensor에서 element의 type을 가르킴.numpy나 tensorflow, torch등이 지원하는 dtype는 다음 URL을 참고.. 2024. 3. 15.
[DL] Tensor 간의 변환: NumPy, PyTorch, TensorFlow pytorch와 numpy의 경우, 텐서를 추상화하고 있는 tensor와 ndarray 를 제공하며, 이 둘은 zero-copy interoperability를 가진다고 말할 수 있을 정도로 상호호환이 가능하다. TensorFlow도 numpy와 상당히 연관되어 있으나, 타입 변환에 있어서 pytorch보다는 불편한 부분이 있다.from 파이썬 시퀀스 타입 (built-in) to 텐서 (numpy, tf, torch)Python의 Sequence Type인 list, tuple 등을 통해다음의 Tensor 인스턴스를 만들 수 있음.np.arraytorch.tensortf.constant (or tf.Variable)t = (1,2,3,4,5,6)a = np.array(t)a_tf = tf.const.. 2024. 3. 15.
728x90
반응형