본문 바로가기
728x90
반응형

tensor13

[PyTorch] tensor의 vectorized operation PyTorch에서 제공하는 Tensor OperatorsPyTorch에서 제공하는 텐서 연산(operator)은homogeneous하고 contiguous한 텐서에 대해모든 element에 동일한 연산을 적용하도록 설계된vectorized operation의 형태를 취함.다른 이름으로 elementwise operation이라고도 불림.이는 파이썬의 반복문 기반 연산에 비해압도적으로 빠른 속도를 제공하며,단일 연산자 호출만으로 전체 텐서에 대한 연산을 수행할 수 있게 함.PyTorch의 elementwise 연산은NumPy의 ufunc과 기능적으로 유사한 역할(아래 3가지 참고)을 수행하지만,broadcasting 처리elementwise kernel 처리dtype promotion 처리보다 광범위한 b.. 2025. 12. 4.
[DL] Tensor 다루기 기초 - PyTorch 중심 https://dsaint31.tistory.com/891 [ML] Tensor: Scalar, Vector, Matrix.Tensor 종류1. Scalar (0차원 tensor)하나의 숫자로 표현되는 가장 기본적인 형태.크기(magnitude)만을 가지며 방향은 없음.예시: 온도(25°C), 나이(20), 가격(1000원)# 파이썬/NumPy에서의 표현scalar = 5.02. Vector (dsaint31.tistory.comhttps://dsaint31.tistory.com/456 [Programming] Primitive Data Type : C, C++, NumPy, TorchPrimitive Data Type이(Unboxed type)란?C, C++, NumPy, PyTorch, TensorF.. 2025. 3. 7.
[DL] Tensor: Random Tensor 만들기 (NumPy, PyTorch) Tensor: Random Tensor 만들기 (NumPy, PyTorch)Random value를 얻는데 이용되는 Probability Distribution에 따라 크게 2가지로 나눌 수 있음.Uniform DistributionNormal Distribution 0. Uniform DistributionRandom Variable이 가질 수 있는 값들이 모두 같은 확률을 가짐.int형 element를 가지는 tensor를 반환하는 것들과float형 element를 가지는 tensor를 반환하는 것으로 크게 나눌 수 있음.가장 대표적인 함수 이름으로는 randint와 rand 가 있음.0.0 randint가장 대표적인 int형 element를 가지는 random tensor를 생성하는데 사용됨.다음과.. 2024. 3. 29.
[DL] Tensor에서 maximum, minimum 찾기 NumPy 의 ndarray에서np.max 와 np.min 함수를 이용하여 최대, 최소인 값을 구함.특정 축을 axis parameter로 지정하여 구할 수 있음 (결과는 해당 axis가 1이 됨.)np.argmax 와 na.argmin 함수를 이용하여 최대, 최소인 값의 index를 반환함.PyTorch 의 tensor 에서torch.max와 torch.min 함수를 사용하여 최대값과 최소값을 구함.특정 축을 dim parameter로 지정하여 구할 수 있음 (결과는 해당 축이 1이 됨.).특정 축을 지정할 경우, torch.max와 torch.min은 indices를 같이 반환함.torch.argmax 와 torch.argmin 함수를 이용하여 최대, 최소값의 indices를 반환함.# 다음은 3x2.. 2024. 3. 28.
[DL] PyTorch: view, data, and detach PyTorch에서 tensor.view()와 tensor.data를 제공하며 이들은 다음과 같은 용도로 사용됨.tensor.view()tensor.view(*shape) 메서드는 tensor 인스턴스의 dimension을 수정하는데 사용됨.이 메서드는 새로운 shape를 가진 같은 데이터의 새로운 tensor 인스턴스를 반환하지만, 원본 tensor 인스턴스와 underlying memory를 공유하여 같은 데이터를 공유함.즉, 메모리를 재할당하지 않고 tensor의 shape와 각 축의 stride만이 바뀜.view()를 사용할 때 반환되는 tensor 인스턴스는 기본 텐서 인스턴스와 데이터를 공유하기 때문에,하나를 변경하면 다른 하나도 변경됨.이는 Nueral Network를 구축할 때, 각 laye.. 2024. 3. 22.
[DL] Storage: PyTorch 텐서를 위한 메모리 관리 Storage는 Tensor 인스턴스의 실제 데이터가 저장되는 1D Numerical Array를 관리함.여러 Tensor 인스턴스들이 같은 storage를 공유할 수 있음. Storage는memory에서 contiguous data block를 관리하며,컴퓨터의 memory에서 homogeneous and contiguous array의 특징상 1D 임.cpu 또는 gpu 등의 memory의 실제 data가 저장된 contiguous block을 관리.다양한 shape의 Tensor 인스턴스들은 자신의 storage인스턴스를 통해 data block을 관리함.어찌 보면 Tensor 인스턴스들은 고유한 shape, stride, offset 을 가진 일종의 View에 해당한다. 참고: 다음 URL에서 c.. 2024. 3. 21.
728x90
반응형