728x90 반응형 Python181 [matplotlib] plt.ion 과 plt.ioff 를 통한 대화형으로 그래프 그리기 이 문서는Python REPL(Read-Eval-Print Loop) 환경에서matplotlib을 대화형으로 사용하는 예제임. 아래 코드는 Python 명령 프롬프트나 IPython과 같은 REPL 환경에서 단계별로 실행할 수 있음:# 먼저 필요한 라이브러리를 importimport matplotlib.pyplot as pltimport numpy as np# 대화형(REPL, or interactive) 모드 활성화plt.ion()# 데이터 생성x = np.linspace(0, 10, 100)y = np.sin(x)# 그래프 생성fig, ax = plt.subplots()line, = ax.plot(x, y, 'b-')ax.set_title('Interactive Sine Wave')ax.set_xla.. 2025. 3. 24. [Py] 객체(object)에 대한 정보 확인하기 Python에서 object(객체)란?type, id, refcount, value 를 속성으로 가지고 있는 a chunk of data.https://dsaint31.tistory.com/517 [Python] Variable (and Object)Variable (and Object)1. 정의Python에서 Variable은 Memory에 할당된 Object를 참조하는 Name (=Reference, Identifier)에 불과하다.이 문서에서 Object는 Python에서의 Object로 type과 value, ID (CPython에서는 할당된 memory addrdsaint31.tistory.com 1. Data Type (or Class)type(obj)# obj.__class__ # dunde.. 2025. 3. 19. [Ex] Numeric Datatype 다음의 연산들의 결과를 구해보고 그 이유를 설명해보라. Ex 01result1 - 5 까지의 값을 출력하는 코드를 작성하고, 그 결과값을 comment로 기재하라.a = 15b = 4result1 = a + bresult2 = a - bresult3 = a * bresult4 = a / bresult5 = a // bEx 02result1 - 3 까지의 값을 출력하는 코드를 작성하고, 그 결과값을 comment로 기재하라.a = 17b = 5result1 = a % bresult2 = a ** 2result3 = b ** 3Ex 03최종 x의 값은?x = 10x += 5x *= 2x //= 3x %= 4Ex 04result의 값은?result = 2 + 3 * 4 ** 2 - 8 / 4Ex 05result1-4 의 데이터 타입과 값을 출력하는 코드를 작성하고.. 2025. 3. 17. [PyTorch] dtype 단축메서드로 바꾸기 아래의 URL에서 간단히 다룬 단축 method들을 이용한 방식 (to나 type이 아닌)을 설명하는 문서임.2024.03.15 - [Python] - [DL] Tensor: dtype 변경(casting) 및 shape 변경. [DL] Tensor: dtype 변경(casting) 및 shape 변경.Tensor를 추상화하고 있는 class로는numpy.array: numpy의 ndarraytorch.tensortensorflow.constant: (or tensorflow.Variable)이 있음. 이들은 Python의 sequence types과 달리 일반적으로 다음과 같은 특징을 지님.데이터들이ds31x.tistory.com사용예제: 정수형import torchb = torch.rand((2,3).. 2025. 3. 14. [PyTorch] in-place 연산이란? in-place 연산이란?in-place 연산은 원본 데이터 구조를 직접 수정하여 별도의 복사본을 만들지 않는 연산 방식을 가리킴.메모리 효율성이 높지만,원본 데이터가 변경된다는 점을 주의해야 함.주의할 점은 in-place 연산을 사용할 때 자동 미분(autograd)에서 문제가 발생할 수 있음.requires_grad=True인 텐서에 대해 in-place 연산을 수행하면계산 그래프가 올바르게 유지되지 않을 수 있으므로 주의해야 함.autograd를 사용할 때는 in-place 연산을 피해야 함.즉, 모델 학습 중에는 in-place 연산을 사용하지 말 것.PyTorch에서의 in-place 연산PyTorch에서는 method 이름 끝에 언더스코어(_)를 붙여 in-place operation 임을 .. 2025. 3. 13. [PyTorch] flattenning - Tensor's methods PyTorch에서 Multi-dimensional tensor 를 1차원(1D)으로 변환을 지원하는 여러 방법(주로 method.)이 있음.단순히 view를 제공하는지 아니면 복사본인지에 대한 이해가 필요함.NumPy의 ndarray의 경우는 다음을 참고:2024.09.09 - [Python] - [NumPy] ravel() 메서드 with flatten() 메서드 [NumPy] ravel() 메서드 with flatten() 메서드NumPy의 ndarray.ravel() 메서드는다차원 배열을 1차원 배열로 평탄화(flatten)하는 데 사용됨.기본적으로 이 메서드는 원본 배열의 데이터에 대한 뷰(view)를 반환: 즉 복사본을 생성하지 않고 메모리를ds31x.tistory.com1. tensor.vie.. 2025. 3. 13. 이전 1 2 3 4 5 6 ··· 31 다음 728x90 반응형