728x90 반응형 Python288 [Py] collections 모듈 (summary) - 작성중 Python의 collections 모듈은 파이썬의 built-in 자료구조를 확장한 special container 클래스들을 제공함.1. Counter요소의 개수를 세는 dictionary의 subclass.해시 가능한 객체의 카운트를 저장함.from collections import Counterc = Counter(['apple', 'orange', 'apple', 'banana', 'apple'])print(c) # Counter({'apple': 3, 'orange': 1, 'banana': 1})2. defaultdict:기본값을 제공하는 함수를 지정하여 기본값을 제공역시 dictionary의 subclass.존재하지 않는 키에 접근할 때 에러 대신 지정된 함수를 호출하여 기본값을 반환.f.. 2025. 4. 4. [Py] print 함수 Python의 print() 함수란?print()는 Python의 built-in 함수로, 표준 출력(stdout) 에 메시지나 데이터를 문자열 형태로 출력하는 기능을 제공. 2024.09.11 - [CE] - [CE] Stream이란 [CE] Stream이란Stream:데이터를 연속적으로 흐르는 방식으로 처리한다는 개념으로,데이터의 입출력을 일종의 bit (or byte) 들의 흐름으로 여겨서 처리하는 것으로 생각하고이와 같은 방식으로 I/O가 이루어지는 대ds31x.tistory.comhttps://dsaint31.me/mkdocs_site/CE/ch10/ce10_2_04_stdio/#standard-io-library_1 BMEI/O Stream 과 Standard I/O Library 1. Str.. 2025. 4. 2. [PyTorch] autograd 심화: grad_fn 과 custom operation 만들기 1. PyTorch Autograd 메커니즘 이해1-1. Tensor의 grad_fn과 연산 그래프 추적 방법PyTorch tensor의 grad_fn은 마지막 operation만 표시하는 attribute.전체 computation graph 확인을 위한 next_functions attribute의 활용.재귀적 접근을 통한 전체 operation history의 추적.def print_grad_graph(grad_fn, level=0): print(' ' * level, grad_fn) if hasattr(grad_fn, 'next_functions'): for next_func in grad_fn.next_functions: if next_func[0] i.. 2025. 3. 28. [Py] Bitwise Operator Operand로 int 와 bool , 또는 byte와 bytesarrays의 각 요소 (각 요소가 중요!!)만 사용할 수 있다.bytes 나 bytearrays는 직접 사용이 안되고 각 요소 단위로 꺼내서 처리해야 한다.참고로,Bitwise Operator는 Tensor 등에서 Element-wise로 동작하며 때문에 그 중요도가 커짐.그 외에선 많이 쓰이진 않음. Python의 Bitwise Operators의 우선순위와 동작은 다음과 같음(이해를 위해 8비트 기준으로 기재했으나 실제로는 Python의 int는 가변 길이 정수로 비트 수에 제한이 없다는 점을 명심) Bitwise Operator를 연산자 precedence 에 따라 기재함:1. ~ (비트 NOT, complement)각 bit를 반.. 2025. 3. 26. [matplotlib] plt.ion 과 plt.ioff 를 통한 대화형으로 그래프 그리기 이 문서는Python REPL(Read-Eval-Print Loop) 환경에서matplotlib을 대화형(interactive)으로 사용하는 예제임. plt.ion() 은 interactive on을 줄인 이름 그대로, matplotlib의 interactive mode를 활성화함.IPython shell이나 Python 기본 interactive shell 에서 유용하게 각 statement의 실행마다 화면이 갱신됨.plt.pause(0.1) 등과 같이 사용할 경우, animation 시뮬레이션이 가능.하지만, Jupyter Notebook이나 Colab 처럼 브라우저 기반인 경우엔 그 효과가 없음%matplotlib inline 이 기본이기 때문에 셀실행마다 static image로 출력됨.별도의 창.. 2025. 3. 24. [Py] 객체(object)에 대한 정보 확인하기 Python에서 object(객체)란?type, id, refcount, value 를 속성으로 가지고 있는 a chunk of data.variable과 object에 대한 보다 자세한 내용은 다음을 참고: 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프로그래밍에서 object에 .. 2025. 3. 19. 이전 1 ··· 17 18 19 20 21 22 23 ··· 48 다음 728x90 반응형