<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-4881868893095669586</id><updated>2025-10-27T10:45:34.249+09:00</updated><category term="python"/><category term="파이썬"/><category term="numpy"/><category term="app engine"/><category term="django"/><category term="파이썬개발"/><category term="Poetry"/><category term="PyPI"/><category term="arange"/><category term="array"/><category term="collections"/><category term="ctypes"/><category term="ones"/><category term="regex"/><category term="regular expression"/><category term="zeros"/><category term="zip"/><category term="연산자"/><category term="이진수"/><category term="정규식"/><category term="정수"/><category term="파이썬튜토리얼"/><category term="파이썬패키징"/><category term="패키지관리"/><category term="//"/><category term="16진수"/><category term="2차원"/><category term="3.10"/><category term="3.9"/><category term="=="/><category term="BytesIO"/><category term="Counter"/><category term="DevOps"/><category term="GIL"/><category term="IDE"/><category term="PEP517"/><category term="Pycharm"/><category term="Vscode"/><category term="anigravity"/><category term="annotation"/><category term="array join"/><category term="backreferece"/><category term="broadcasting"/><category term="c binding"/><category term="c++"/><category term="case"/><category term="case class"/><category term="chardet"/><category term="chatgpt"/><category term="class"/><category term="context"/><category term="dalle3"/><category term="dataclass"/><category term="debug"/><category term="decorator"/><category term="dedent"/><category term="dict"/><category term="else"/><category term="embedding"/><category term="empty"/><category term="env"/><category term="extending"/><category term="eye"/><category term="f-string"/><category term="file"/><category term="for"/><category term="format"/><category term="gcd"/><category term="google trends"/><category term="greedy"/><category term="group"/><category term="groupby"/><category term="hstack"/><category term="indent"/><category term="indexing"/><category term="is"/><category term="iterable"/><category term="iterator"/><category term="itertools"/><category term="jpg"/><category term="lambda"/><category term="lcm"/><category term="linespace"/><category term="linspace"/><category term="linux"/><category term="logspace"/><category term="lstrip"/><category term="manager"/><category term="marshaling"/><category term="match"/><category term="math"/><category term="namedtuple"/><category term="nextafter"/><category term="non greedy"/><category term="ocr"/><category term="open"/><category term="openai"/><category term="ordereddict"/><category term="pdf"/><category term="pdf 변환"/><category term="perl"/><category term="product"/><category term="pybind"/><category term="python zip"/><category term="pytorch"/><category term="pytube"/><category term="reStructure"/><category term="removeprefix"/><category term="removesuffix"/><category term="rstrip&#xa;대안"/><category term="slicing"/><category term="sort"/><category term="sphinx"/><category term="string interpolation"/><category term="sub"/><category term="switch"/><category term="ternary"/><category term="tesseract"/><category term="thread"/><category term="transpose"/><category term="type hint"/><category term="ubuntu"/><category term="ulp"/><category term="vertical"/><category term="vim"/><category term="vstack"/><category term="webframework"/><category term="whisper"/><category term="with"/><category term="wrap"/><category term="wraptext"/><category term="xkcd"/><category term="zfill"/><category term="zip함수"/><category term="|"/><category term="개발팁"/><category term="개발환경"/><category term="곱집합"/><category term="나눗셈"/><category term="데이터 클래스"/><category term="데카르드곱"/><category term="데코레이터"/><category term="디버그"/><category term="딕셔너리"/><category term="람다"/><category term="마샬링"/><category term="메모리최적화"/><category term="문자열 보간"/><category term="바다코끼리"/><category term="배열"/><category term="백엔드개발"/><category term="삼항"/><category term="생성"/><category term="생성&#xa;초기화"/><category term="성능개선"/><category term="소수점"/><category term="수직편집"/><category term="예제"/><category term="오프라인 설치"/><category term="우분투"/><category term="유니온"/><category term="이스터에그"/><category term="이터레이터"/><category term="정렬"/><category term="조건문"/><category term="최대"/><category term="최소"/><category term="코딩팁"/><category term="탐욕"/><category term="테크니컬"/><category term="파이썬 3.9"/><category term="파이썬 venv"/><category term="패턴매칭"/><category term="퍄이썬"/><category term="함수주석"/><title type='text'>PythonEngine</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://pyengine.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4881868893095669586/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://pyengine.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/4881868893095669586/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>91</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4881868893095669586.post-6798931430545750417</id><published>2025-03-04T00:00:00.025+09:00</published><updated>2025-03-04T00:00:00.230+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="env"/><category scheme="http://www.blogger.com/atom/ns#" term="python"/><title type='text'>Python-dotenv로 환경 변수 관리하기</title><content type='html'>
&lt;pre class=&quot;markdown&quot;&gt;
&lt;xmp&gt;
 

# Python-dotenv로 환경 변수 관리하기

환경 변수 관리는 모든 개발 프로젝트에서 중요한 부분입니다. 특히 API 키, 데이터베이스 비밀번호와 같은 민감한 정보를 안전하게 관리하기 위해서는 적절한 도구가 필요합니다. Python-dotenv는 이러한 환경 변수를 효율적으로 관리할 수 있게 도와주는 파이썬 라이브러리입니다. 이 도구를 사용하면 `.env` 파일에 환경 변수를 저장하고 애플리케이션에서 쉽게 불러올 수 있어, 개발과 배포 과정을 훨씬 단순화할 수 있습니다.

개발자로서 환경 변수를 하드코딩하거나 여러 설정 파일을 관리하는 번거로움을 겪어보셨나요? 또는 팀 프로젝트에서 각기 다른 개발 환경을 일관되게 유지하는 어려움을 경험해보셨나요? Python-dotenv는 이러한 문제를 해결하고 코드의 보안성과 유지보수성을 향상시키는 데 큰 도움이 됩니다.

이 글에서는 Python-dotenv의 기본 개념부터 실제 프로젝트에 적용하는 방법까지 단계별로 알아보겠습니다. 간단한 예제와 함께 이 도구의 장점을 충분히 활용할 수 있는 방법을 소개해 드리겠습니다.

## 🔍 Python-dotenv란 무엇인가?

Python-dotenv는 `.env` 파일에서 환경 변수를 로드하고 관리하는 파이썬 패키지입니다. 이 라이브러리의 주요 목적은 애플리케이션 설정과 민감한 정보를 코드와 분리하여 관리하는 것입니다.

일반적으로 환경 변수는 운영체제 수준에서 설정되는데, Python-dotenv를 사용하면 프로젝트 디렉토리 내의 `.env` 파일에 이러한 변수들을 정의하고 파이썬 애플리케이션에서 쉽게 접근할 수 있습니다.

```python
# 운영체제 환경 변수 설정 없이도 .env 파일의 값을 가져올 수 있습니다
DATABASE_URL=postgresql://user:password@localhost/dbname
API_KEY=your_secret_api_key
DEBUG=True
```

## ⚙️ 설치 및 기본 사용법

Python-dotenv는 pip를 사용하여 쉽게 설치할 수 있습니다:

```bash
pip install python-dotenv
```

설치 후에는 다음과 같이 간단하게 사용할 수 있습니다:

## 🚀 Python-dotenv의 주요 기능과 활용법

### 1. 다양한 환경별 설정 관리 🌍

개발, 테스트, 프로덕션 등 다양한 환경에서 서로 다른 설정을 사용해야 할 때 Python-dotenv가 큰 도움이 됩니다. 각 환경별로 다른 `.env` 파일을 만들어 관리할 수 있습니다.

```
# .env.development
DEBUG=True
DATABASE_URL=sqlite:///dev.db

# .env.production
DEBUG=False
DATABASE_URL=postgresql://user:password@production-server/dbname
```

이렇게 환경별로 다른 파일을 로드하는 방법:

```python
import os
from dotenv import load_dotenv

# 환경에 따라 다른 .env 파일 로드
env_name = os.environ.get(&quot;ENV_NAME&quot;, &quot;development&quot;)
load_dotenv(f&quot;.env.{env_name}&quot;)

# 이제 적절한 환경 변수가 로드됩니다
debug = os.environ.get(&quot;DEBUG&quot;)
```

### 2. 중첩된 변수 지원 ⛓️

Python-dotenv는 `.env` 파일 내에서 다른 변수를 참조하는 중첩 변수를 지원합니다:

```
# .env 파일
BASE_URL=https://api.example.com
API_VERSION=v1
API_ENDPOINT=${BASE_URL}/${API_VERSION}
```

이 기능을 사용하면 반복적인 설정을 줄이고 더 체계적으로 환경 변수를 관리할 수 있습니다.

### 3. 파이썬 프레임워크와의 통합 예제 🔄

Flask나 Django와 같은 웹 프레임워크에서 Python-dotenv를 활용하는 예제를 살펴보겠습니다:

## 🔒 보안과 버전 관리에서의 모범 사례

Python-dotenv를 사용할 때 몇 가지 중요한 보안 사항과 버전 관리 모범 사례가 있습니다:

### 민감한 정보 보호 ✅

- ✔️ `.env` 파일은 항상 `.gitignore`에 추가하여 버전 관리에서 제외
- ✔️ 대신 `.env.example` 파일을 만들어 필요한 변수 형식을 공유
- ✔️ 프로덕션 환경의 키는 안전한 비밀 저장소 또는 클라우드 서비스의 환경 변수 관리 도구 사용

```
# .gitignore 파일에 추가
.env
.env.*
!.env.example
```

```
# .env.example 파일 (실제 값 없이 형식만 공유)
DATABASE_URL=postgresql://user:password@host/dbname
API_KEY=your_api_key_here
DEBUG=True
```

## 🔧 실전 활용 사례: 웹 크롤링 프로젝트

개인적으로 웹 크롤링 프로젝트를 진행하면서 Python-dotenv를 처음 접하게 되었습니다. 여러 API 키와 데이터베이스 접속 정보를 관리해야 했는데, 이를 코드에 하드코딩하는 것은 보안상 위험했고, 팀원들과 공유하기도 어려웠습니다.

Python-dotenv를 도입한 후에는 다음과 같은 이점을 경험했습니다:

1. 개발자마다 자신의 API 키를 `.env` 파일에 별도로 관리할 수 있었습니다.
2. 코드 리뷰 과정에서 민감한 정보가 노출되지 않았습니다.
3. 테스트 환경과 프로덕션 환경을 쉽게 전환할 수 있었습니다.

간단한 웹 크롤링 예제로 Python-dotenv의 실제 사용법을 알아보겠습니다:

```python
# .env 파일 내용:
# API_KEY=your_api_key_here
# USER_AGENT=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36
# PROXY_URL=http://proxy.example.com:8080
# MAX_REQUESTS=100
# SAVE_DIRECTORY=./data

# scraper.py
import os
import requests
from dotenv import load_dotenv, find_dotenv

# 자동으로 .env 파일 찾아 로드
load_dotenv(find_dotenv())

def get_api_data(endpoint):
    &quot;&quot;&quot;API에서 데이터를 가져오는 함수&quot;&quot;&quot;
    headers = {
        &#39;User-Agent&#39;: os.environ.get(&#39;USER_AGENT&#39;),
        &#39;Authorization&#39;: f&quot;Bearer {os.environ.get(&#39;API_KEY&#39;)}&quot;
    }
    
    proxies = None
    if os.environ.get(&#39;PROXY_URL&#39;):
        proxies = {
            &#39;http&#39;: os.environ.get(&#39;PROXY_URL&#39;),
            &#39;https&#39;: os.environ.get(&#39;PROXY_URL&#39;)
        }
    
    response = requests.get(
        endpoint,
        headers=headers,
        proxies=proxies
    )
    
    return response.json()

def save_data(data, filename):
    &quot;&quot;&quot;데이터를 파일로 저장하는 함수&quot;&quot;&quot;
    save_dir = os.environ.get(&#39;SAVE_DIRECTORY&#39;, &#39;./data&#39;)
    
    # 디렉토리가 없으면 생성
    if not os.path.exists(save_dir):
        os.makedirs(save_dir)
        
    file_path = os.path.join(save_dir, filename)
    
    with open(file_path, &#39;w&#39;) as f:
        f.write(str(data))
    
    return file_path

if __name__ == &quot;__main__&quot;:
    # 환경 변수 확인 및 기본값 설정
    max_requests = int(os.environ.get(&#39;MAX_REQUESTS&#39;, 10))
    
    print(f&quot;Starting web scraping with {max_requests} max requests&quot;)
    print(f&quot;Using API key: {os.environ.get(&#39;API_KEY&#39;)[:5]}...&quot;)
    
    # API에서 데이터 가져오기
    data = get_api_data(&quot;https://api.example.com/data&quot;)
    
    # 데이터 저장
    file_path = save_data(data, &quot;scraped_data.json&quot;)
    print(f&quot;Data saved to {file_path}&quot;)
```

## 🌟 Python-dotenv의 고급 기법

Python-dotenv를 더 효과적으로 활용할 수 있는 몇 가지 고급 기법을 알아보겠습니다:

### 1. 커맨드라인에서 환경 변수 오버라이드 ⚡

Python-dotenv는 `.env` 파일의 환경 변수보다 이미 설정된 OS 환경 변수를 우선시합니다. 이를 활용하면 특정 상황에서 임시로 환경 변수를 오버라이드할 수 있습니다:

```bash
# 일시적으로 다른 데이터베이스 사용
DATABASE_URL=sqlite:///test.db python app.py
```

### 2. .env 파일 위치 커스터마이징 ⚡

프로젝트 구조에 따라 `.env` 파일의 위치를 지정할 수 있습니다:

```python
from dotenv import load_dotenv
import os

# 특정 경로의 .env 파일 로드
load_dotenv(&quot;/path/to/project/.env&quot;)

# 또는 상대 경로 사용
load_dotenv(os.path.join(os.path.dirname(__file__), &quot;..&quot;, &quot;.env&quot;))
```

### 3. 환경 변수 재정의 방지 ⚡

이미 설정된 환경 변수를 `.env` 파일로 덮어쓰지 않게 하려면 `override=False` 옵션을 사용합니다:

```python
from dotenv import load_dotenv

# 이미 존재하는 환경 변수는 유지
load_dotenv(override=False)
```

## 📊 마무리: Python-dotenv로 환경 변수 관리 시작하기

Python-dotenv는 간단하지만 강력한 도구로, 파이썬 프로젝트에서 환경 변수를 효율적으로 관리할 수 있게 해줍니다. 특히 민감한 정보를 코드에서 분리하고, 여러 개발 환경에서 일관된 설정을 유지하는 데 큰 도움이 됩니다.

이 글에서 소개한 기본 개념과 예제를 통해 Python-dotenv를 프로젝트에 도입하는 데 필요한 지식을 얻으셨기를 바랍니다. 소규모 개인 프로젝트부터 대규모 팀 프로젝트까지, Python-dotenv는 환경 변수 관리를 단순화하고 보안을 강화하는 데 기여할 것입니다.

프로젝트에 Python-dotenv를 도입할 때는 다음 단계를 따라보세요:

1. `pip install python-dotenv`로 설치
2. 프로젝트 루트에 `.env` 파일 생성
3. `.gitignore`에 `.env` 파일 추가
4. 예제 형식을 보여주는 `.env.example` 파일 생성
5. 코드에 `load_dotenv()`를 추가하여 환경 변수 로드

이러한 단계를 통해 코드의 유지보수성과 보안성을 한 단계 높일 수 있을 것입니다. 환경 변수 관리를 체계화하여 개발 과정이 더욱 순탭해지길 바랍니다!


&lt;/xmp&gt;
&lt;/pre&gt;
</content><link rel='replies' type='application/atom+xml' href='http://pyengine.blogspot.com/feeds/6798931430545750417/comments/default' title='댓글'/><link rel='replies' type='text/html' href='http://pyengine.blogspot.com/2025/03/python-dotenv.html#comment-form' title='0개의 덧글'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4881868893095669586/posts/default/6798931430545750417'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4881868893095669586/posts/default/6798931430545750417'/><link rel='alternate' type='text/html' href='http://pyengine.blogspot.com/2025/03/python-dotenv.html' title='Python-dotenv로 환경 변수 관리하기'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4881868893095669586.post-1386363562230353697</id><published>2025-02-26T00:00:00.002+09:00</published><updated>2025-02-26T00:00:00.133+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="DevOps"/><category scheme="http://www.blogger.com/atom/ns#" term="Poetry"/><category scheme="http://www.blogger.com/atom/ns#" term="PyPI"/><category scheme="http://www.blogger.com/atom/ns#" term="python"/><category scheme="http://www.blogger.com/atom/ns#" term="개발환경"/><category scheme="http://www.blogger.com/atom/ns#" term="파이썬개발"/><category scheme="http://www.blogger.com/atom/ns#" term="파이썬튜토리얼"/><category scheme="http://www.blogger.com/atom/ns#" term="파이썬패키징"/><category scheme="http://www.blogger.com/atom/ns#" term="패키지관리"/><title type='text'>Python Poetry를 사용한 파이썬 패키지 개발</title><content type='html'>&lt;h1&gt;🚀 Poetry로 시작하는 프로페셔널 파이썬 패키지 개발: 실전 가이드 2024&lt;/h1&gt;
&lt;p&gt;안녕하세요! 지난번 PEP 517 포스팅에 많은 관심을 보내주셔서 감사합니다. 오늘은 많은 분들이 요청하신 Poetry를 사용한 실전 패키지 개발 가이드를 준비했습니다. 제가 실제 프로젝트에서 Poetry를 도입하면서 겪은 시행착오와 깨달음을 모두 담아보았습니다. 특히 처음 Poetry를 시작하시는 분들이 꼭 알아야 할 내용들을 중심으로 구성했으니, 끝까지 함께해 주세요!&lt;/p&gt;
&lt;h2&gt;🎯 Poetry가 필요한 순간: 실제 사례로 알아보기&lt;/h2&gt;
&lt;p&gt;저는 얼마 전 회사에서 데이터 분석 파이프라인을 개발하는 프로젝트를 맡았습니다. 팀원들과 함께 작업하면서 가장 큰 고민은 &amp;quot;서로 다른 환경에서 어떻게 동일한 결과를 보장할 수 있을까?&amp;quot;였죠. requirements.txt를 사용했지만, 버전 충돌과 환경 불일치 문제가 계속 발생했습니다.&lt;/p&gt;
&lt;p&gt;Poetry를 도입한 후, 이런 문제들이 말끔히 해결되었습니다. 특히 인상적이었던 것은 새로운 팀원이 합류했을 때의 온보딩 시간이 대폭 줄었다는 거예요. 단순히 &lt;code&gt;poetry install&lt;/code&gt; 한 줄로 모든 설정이 끝났으니까요!&lt;/p&gt;
&lt;h2&gt;💫 Poetry 설치와 프로젝트 시작하기&lt;/h2&gt;
&lt;p&gt;먼저 Poetry를 설치하는 방법부터 알아볼까요?&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;# Poetry 설치
curl -sSL https://install.python-poetry.org | python3 -

# 새 프로젝트 시작
poetry new my-awesome-package
cd my-awesome-package

# 기존 프로젝트에 Poetry 적용
poetry init
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;🛠️ Poetry의 핵심 기능 마스터하기&lt;/h2&gt;
&lt;h3&gt;의존성 관리&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;language-toml&quot;&gt;[tool.poetry.dependencies]
python = &amp;quot;^3.8&amp;quot;
requests = &amp;quot;^2.28.0&amp;quot;
pandas = &amp;quot;&amp;gt;=1.4.0&amp;quot;

[tool.poetry.dev-dependencies]
pytest = &amp;quot;^7.1.1&amp;quot;
black = &amp;quot;^22.3.0&amp;quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;가상환경 관리&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;# 가상환경 생성 및 활성화
poetry shell

# 의존성 설치
poetry install

# 새 패키지 추가
poetry add requests
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;📊 Poetry vs 다른 패키지 관리 도구 비교&lt;/h2&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;기능&lt;/th&gt;
&lt;th&gt;Poetry&lt;/th&gt;
&lt;th&gt;Pip+venv&lt;/th&gt;
&lt;th&gt;Pipenv&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;의존성 해결&lt;/td&gt;
&lt;td&gt;⭐⭐⭐⭐⭐&lt;/td&gt;
&lt;td&gt;⭐⭐&lt;/td&gt;
&lt;td&gt;⭐⭐⭐&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;설치 속도&lt;/td&gt;
&lt;td&gt;⭐⭐⭐⭐&lt;/td&gt;
&lt;td&gt;⭐⭐⭐&lt;/td&gt;
&lt;td&gt;⭐⭐&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;사용 편의성&lt;/td&gt;
&lt;td&gt;⭐⭐⭐⭐⭐&lt;/td&gt;
&lt;td&gt;⭐⭐&lt;/td&gt;
&lt;td&gt;⭐⭐⭐&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;러닝커브&lt;/td&gt;
&lt;td&gt;⭐⭐⭐&lt;/td&gt;
&lt;td&gt;⭐⭐⭐⭐⭐&lt;/td&gt;
&lt;td&gt;⭐⭐⭐&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2&gt;✨ Poetry 실전 활용 팁&lt;/h2&gt;
&lt;h3&gt;프로젝트 구조 최적화&lt;/h3&gt;
&lt;p&gt;✔️ &lt;code&gt;src&lt;/code&gt; 레이아웃 사용하기&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;my-project/
├── pyproject.toml
├── README.md
├── src/
│   └── my_package/
│       ├── __init__.py
│       └── main.py
└── tests/
    └── test_main.py
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;패키지 배포 준비&lt;/h3&gt;
&lt;p&gt;✔️ 빌드 및 배포 명령어&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;# 패키지 빌드
poetry build

# PyPI에 배포
poetry publish
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;🚨 자주 발생하는 문제와 해결방법&lt;/h2&gt;
&lt;p&gt;✅ &lt;strong&gt;문제 해결 체크리스트&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;✔️ 가상환경이 제대로 활성화되지 않을 때&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;poetry env list
poetry env remove python
poetry install
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;✔️ 의존성 충돌 발생 시&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;poetry update --lock
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;✔️ 패키지 퍼블리시 오류&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;poetry config pypi-token.pypi your-token
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;마치며&lt;/h2&gt;
&lt;p&gt;Poetry는 현대 파이썬 개발의 필수 도구로 자리잡았습니다. 특히 팀 프로젝트에서 일관된 개발 환경을 유지하고 싶다면, Poetry는 최고의 선택이 될 것입니다. 이 가이드가 여러분의 패키지 개발 여정에 도움이 되었기를 바랍니다.&lt;/p&gt;
&lt;p&gt; 궁금하신 점이나 공유하고 싶은 경험이 있다면 댓글로 남겨주세요! 😊&lt;/p&gt;
</content><link rel='replies' type='application/atom+xml' href='http://pyengine.blogspot.com/feeds/1386363562230353697/comments/default' title='댓글'/><link rel='replies' type='text/html' href='http://pyengine.blogspot.com/2025/02/python-poetry.html#comment-form' title='0개의 덧글'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4881868893095669586/posts/default/1386363562230353697'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4881868893095669586/posts/default/1386363562230353697'/><link rel='alternate' type='text/html' href='http://pyengine.blogspot.com/2025/02/python-poetry.html' title='Python Poetry를 사용한 파이썬 패키지 개발'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4881868893095669586.post-8480807173626780042</id><published>2025-02-24T00:00:00.001+09:00</published><updated>2025-02-24T00:00:00.118+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="PEP517"/><category scheme="http://www.blogger.com/atom/ns#" term="Poetry"/><category scheme="http://www.blogger.com/atom/ns#" term="PyPI"/><category scheme="http://www.blogger.com/atom/ns#" term="python"/><category scheme="http://www.blogger.com/atom/ns#" term="개발팁"/><category scheme="http://www.blogger.com/atom/ns#" term="파이썬개발"/><category scheme="http://www.blogger.com/atom/ns#" term="파이썬튜토리얼"/><category scheme="http://www.blogger.com/atom/ns#" term="파이썬패키징"/><category scheme="http://www.blogger.com/atom/ns#" term="패키지관리"/><title type='text'>Python PEP 517로 알아보는 파이썬 패키징</title><content type='html'>&lt;h1&gt;🚀 PEP 517로 알아보는 현대적 파이썬 패키징의 모든 것: 초보자도 이해하기 쉬운 가이드&lt;/h1&gt;
&lt;p&gt;안녕하세요! 오늘은 파이썬 개발자라면 한 번쯤 마주치게 되는 패키징 시스템, 특히 PEP 517에 대해 알아보려고 합니다. &amp;quot;setup.py가 뭐죠?&amp;quot;, &amp;quot;왜 패키지 빌드가 자꾸 실패하나요?&amp;quot; 이런 고민을 해보신 적 있으신가요? 걱정 마세요. 오늘 포스팅을 통해 현대적인 파이썬 패키징의 세계로 여러분을 초대합니다.&lt;/p&gt;
&lt;h2&gt;🤔 왜 PEP 517이 필요했을까?&lt;/h2&gt;
&lt;p&gt;제가 처음 파이썬 패키징을 접했을 때의 이야기로 시작해볼까요? 몇 년 전, 저는 작은 유틸리티 라이브러리를 만들어 PyPI에 배포하려 했습니다. &lt;code&gt;setup.py&lt;/code&gt;를 작성하고, 빌드하고... 그런데 이게 웬걸, 로컬에서는 잘 돌아가는데 다른 환경에서는 제대로 설치가 안 되는 거예요!&lt;/p&gt;
&lt;p&gt;알고 보니 &lt;code&gt;setup.py&lt;/code&gt;가 실행될 때 예상치 못한 코드가 실행되고 있었고, 시스템 파이썬 환경이 오염되는 문제도 있었습니다. 이런 문제들을 해결하기 위해 PEP 517이 등장했답니다.&lt;/p&gt;
&lt;h2&gt;📦 PEP 517이 가져온 혁신적인 변화&lt;/h2&gt;
&lt;p&gt;이제 패키징은 정말 간단해졌습니다! 예전에는 이런 복잡한 &lt;code&gt;setup.py&lt;/code&gt;를 작성해야 했는데요:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-python&quot;&gt;from setuptools import setup, find_packages

setup(
    name=&amp;quot;my-complex-package&amp;quot;,
    version=&amp;quot;0.1.0&amp;quot;,
    packages=find_packages(),
    install_requires=[
        &amp;quot;requests&amp;gt;=2.22.0&amp;quot;,
        &amp;quot;pandas&amp;gt;=1.0.0&amp;quot;,
    ],
    # ... 더 많은 복잡한 설정들
)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;PEP 517 덕분에 이제는 깔끔한 &lt;code&gt;pyproject.toml&lt;/code&gt;로 대체할 수 있습니다:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-toml&quot;&gt;[build-system]
requires = [&amp;quot;poetry-core&amp;gt;=1.0.0&amp;quot;]
build-backend = &amp;quot;poetry.core.masonry.api&amp;quot;

[tool.poetry]
name = &amp;quot;my-simple-package&amp;quot;
version = &amp;quot;0.1.0&amp;quot;
description = &amp;quot;A sample package&amp;quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;🔍 주요 빌드 도구 비교&lt;/h2&gt;
&lt;p&gt;현대 파이썬 패키징 도구들을 한눈에 비교해볼까요?&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;도구&lt;/th&gt;
&lt;th&gt;특징&lt;/th&gt;
&lt;th&gt;추천 사용 사례&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Poetry&lt;/td&gt;
&lt;td&gt;의존성 관리가 깔끔함&lt;/td&gt;
&lt;td&gt;실무 프로젝트&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Flit&lt;/td&gt;
&lt;td&gt;설정이 매우 간단함&lt;/td&gt;
&lt;td&gt;작은 라이브러리&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;PDM&lt;/td&gt;
&lt;td&gt;Poetry의 대안, 가볍고 빠름&lt;/td&gt;
&lt;td&gt;중소규모 프로젝트&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Hatch&lt;/td&gt;
&lt;td&gt;최신 기능 지원&lt;/td&gt;
&lt;td&gt;신규 프로젝트&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2&gt;⚡ PEP 517 도입의 장단점&lt;/h2&gt;
&lt;p&gt;✔️ &lt;strong&gt;장점&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;환경 격리로 안전한 빌드1&lt;/li&gt;
&lt;li&gt;명확한 의존성 관리&lt;/li&gt;
&lt;li&gt;재현 가능한 빌드 환경&lt;/li&gt;
&lt;li&gt;다양한 빌드 도구 선택 가능&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;❌ &lt;strong&gt;단점&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;기존 프로젝트 마이그레이션 필요&lt;/li&gt;
&lt;li&gt;새로운 도구 학습 곡선&lt;/li&gt;
&lt;li&gt;일부 레거시 도구와의 호환성 이슈&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;🎯 실전 활용 팁&lt;/h2&gt;
&lt;p&gt;처음 PEP 517을 도입할 때 이런 팁들이 도움될 거예요:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;✨ 새 프로젝트는 Poetry나 PDM으로 시작하기&lt;/li&gt;
&lt;li&gt;✨ &lt;code&gt;pyproject.toml&lt;/code&gt;을 버전 관리에 포함하기&lt;/li&gt;
&lt;li&gt;✨ 빌드 의존성은 최소한으로 유지하기&lt;/li&gt;
&lt;li&gt;✨ 가상환경 사용은 필수!&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;마치며&lt;/h2&gt;
&lt;p&gt;파이썬 패키징의 새로운 표준, PEP 517은 개발자들의 삶을 한결 편하게 만들어주고 있습니다. 특히 처음 파이썬 패키지를 만들어보시는 분들이라면, PEP 517 기반의 현대적인 도구들을 사용하시는 것을 추천드립니다.&lt;/p&gt;
</content><link rel='replies' type='application/atom+xml' href='http://pyengine.blogspot.com/feeds/8480807173626780042/comments/default' title='댓글'/><link rel='replies' type='text/html' href='http://pyengine.blogspot.com/2025/02/python-pep-517.html#comment-form' title='0개의 덧글'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4881868893095669586/posts/default/8480807173626780042'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4881868893095669586/posts/default/8480807173626780042'/><link rel='alternate' type='text/html' href='http://pyengine.blogspot.com/2025/02/python-pep-517.html' title='Python PEP 517로 알아보는 파이썬 패키징'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4881868893095669586.post-9026133635760306895</id><published>2025-02-22T10:18:00.004+09:00</published><updated>2025-02-22T10:19:07.505+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="BytesIO"/><category scheme="http://www.blogger.com/atom/ns#" term="python"/><category scheme="http://www.blogger.com/atom/ns#" term="메모리최적화"/><category scheme="http://www.blogger.com/atom/ns#" term="백엔드개발"/><category scheme="http://www.blogger.com/atom/ns#" term="성능개선"/><category scheme="http://www.blogger.com/atom/ns#" term="코딩팁"/><category scheme="http://www.blogger.com/atom/ns#" term="테크니컬"/><category scheme="http://www.blogger.com/atom/ns#" term="파이썬개발"/><title type='text'>Python ByteIO활용 하는 메모리 최적화 방법</title><content type='html'>&lt;h1&gt;🚀 BytesIO로 메모리를 최적화하는 놀라운 방법: 파이썬 개발자를 위한 완벽 가이드&lt;/h1&gt;
&lt;p&gt;안녕하세요! 오늘은 파이썬 개발에서 메모리를 최대한 활용하는, BytesIO에 대해 자세히 알아보려고 합니다. 대용량 데이터 처리나 웹 애플리케이션 개발을 하다 보면 메모리 사용량이 늘어나 성능 저하를 경험하신 적 있으시죠? BytesIO를 활용하면 이런 문제를 효과적으로 해결할 수 있습니다. 특히 임시 파일 생성 없이 메모리 내에서 데이터를 효율적으로 다룰 수 있어, 개발자들 사이에서 &amp;quot;메모리 절약의 비법&amp;quot;으로 불리고 있죠.&lt;/p&gt;
&lt;h2&gt;💡 BytesIO란 무엇인가?&lt;/h2&gt;
&lt;p&gt;BytesIO는 Python의 io 모듈에서 제공하는 특별한 클래스입니다. 실제 파일처럼 동작하지만, 디스크에 파일을 만들지 않고 메모리 상에서 바이트 데이터를 처리할 수 있게 해주는 마법 같은 도구입니다.&lt;/p&gt;
&lt;h2&gt;🎯 실제 현장에서의 BytesIO 활용 사례&lt;/h2&gt;
&lt;p&gt;얼마 전 대규모 로그 처리 시스템을 개발하던 중 겪었던 재미있는 경험을 공유해드리겠습니다. 매일 수백 GB의 로그 데이터를 처리해야 했는데, 기존 방식으로는 임시 파일이 너무 많이 생성되어 디스크 공간이 부족해지는 문제가 발생했습니다.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-python&quot;&gt;# 기존 방식의 문제점
for log in large_logs:
    with open(&#39;temp_log.txt&#39;, &#39;w&#39;) as f:
        f.write(log)
    # 로그 처리
    # 임시 파일이 계속 생성되어 디스크 공간 부족!
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;BytesIO를 도입한 후:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-python&quot;&gt;from io import BytesIO

for log in large_logs:
    buffer = BytesIO()
    buffer.write(log.encode())
    buffer.seek(0)
    # 로그 처리
    buffer.close()
    # 임시 파일 없이 메모리에서 처리 완료!
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;📊 기존 방식 vs BytesIO 비교&lt;/h2&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;특징&lt;/th&gt;
&lt;th&gt;일반 파일 I/O&lt;/th&gt;
&lt;th&gt;BytesIO&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;디스크 사용&lt;/td&gt;
&lt;td&gt;높음&lt;/td&gt;
&lt;td&gt;없음&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;처리 속도&lt;/td&gt;
&lt;td&gt;느림&lt;/td&gt;
&lt;td&gt;빠름&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;메모리 효율성&lt;/td&gt;
&lt;td&gt;낮음&lt;/td&gt;
&lt;td&gt;높음&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;자원 관리&lt;/td&gt;
&lt;td&gt;복잡함&lt;/td&gt;
&lt;td&gt;간단함&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2&gt;⚡ BytesIO 사용의 장단점&lt;/h2&gt;
&lt;p&gt;장점:
✔️ 디스크 I/O 없이 빠른 처리 가능
✔️ 메모리 효율적 사용
✔️ 임시 파일 생성 없음
✔️ 멀티스레드 환경에서 안전&lt;/p&gt;
&lt;p&gt;단점:
❌ 대용량 데이터 처리 시 메모리 관리 필요
❌ 영구 저장이 필요한 경우 추가 작업 필요&lt;/p&gt;
&lt;h2&gt;🔍 마치며&lt;/h2&gt;
&lt;p&gt;BytesIO는 파이썬 개발자의 필수 도구입니다. 특히 웹 애플리케이션이나 데이터 처리 시스템을 개발할 때 메모리 최적화의 강력한 해결책이 될 수 있습니다. 지금까지 소개한 방법들을 적용하면서, 여러분의 프로젝트에 가장 적합한 방식을 찾아보시기 바랍니다.&lt;/p&gt;
&lt;hr&gt;

</content><link rel='replies' type='application/atom+xml' href='http://pyengine.blogspot.com/feeds/9026133635760306895/comments/default' title='댓글'/><link rel='replies' type='text/html' href='http://pyengine.blogspot.com/2025/02/byteio.html#comment-form' title='0개의 덧글'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4881868893095669586/posts/default/9026133635760306895'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4881868893095669586/posts/default/9026133635760306895'/><link rel='alternate' type='text/html' href='http://pyengine.blogspot.com/2025/02/byteio.html' title='Python ByteIO활용 하는 메모리 최적화 방법'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4881868893095669586.post-2251284720120640421</id><published>2023-12-03T08:34:00.001+09:00</published><updated>2023-12-03T08:34:00.151+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="django"/><category scheme="http://www.blogger.com/atom/ns#" term="python"/><category scheme="http://www.blogger.com/atom/ns#" term="webframework"/><title type='text'>Python Django Quick-start</title><content type='html'>&lt;h1&gt;Django Quick-start&lt;/h1&gt;
&lt;p&gt;Django는 파이썬에서 사용할 수 있는 강력하고 유연한 웹 프레임워크입니다. Django를 설치하고 간단한 예제 프로젝트를 만드는 단계를 아래에 설명하겠습니다.&lt;/p&gt;
&lt;h3&gt;Django 설치&lt;/h3&gt;
&lt;h4&gt;가상 환경 생성 및 활성화 (선택사항)&lt;/h4&gt;
&lt;p&gt;가상 환경을 사용하면 프로젝트별로 독립적인 파이썬 환경을 만들 수 있어, 여러 프로젝트에서 서로 다른 패키지 버전을 관리하기가 편리합니다.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;python&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;-m&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;venv&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;myvenv
&lt;span class=&quot;w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;source&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;myvenv/bin/activate&lt;span class=&quot;w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;c1&quot;&gt;# Linux나 MacOS에서&lt;/span&gt;
&lt;span class=&quot;w&quot;&gt;  &lt;/span&gt;myvenv&lt;span class=&quot;se&quot;&gt;\S&lt;/span&gt;cripts&lt;span class=&quot;se&quot;&gt;\a&lt;/span&gt;ctivate&lt;span class=&quot;w&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;c1&quot;&gt;# Windows에서&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;파이썬에 내장된 &lt;code&gt;venv&lt;/code&gt; 모듈을 사용하여 새로운 가상 환경을 생성하고, 해당 환경을 활성화합니다. 활성화 후에는 해당 가상 환경 내에서 패키지 설치 및 관리가 이루어집니다.&lt;/p&gt;
&lt;h4&gt;Django 설치&lt;/h4&gt;
&lt;p&gt;pip를 사용하여 Django를 설치합니다.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;pip&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;install&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;django
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;pip는 파이썬의 패키지 관리자로, 파이썬 라이브러리를 쉽게 설치하고 관리할 수 있게 해줍니다.&lt;/p&gt;
&lt;h3&gt;간단한 Django 프로젝트 생성&lt;/h3&gt;
&lt;h4&gt;프로젝트 생성&lt;/h4&gt;
&lt;p&gt;&lt;code&gt;django-admin&lt;/code&gt; 도구를 사용하여 새 프로젝트를 생성합니다.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;django-admin&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;startproject&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;myproject
&lt;span class=&quot;w&quot;&gt;   &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;cd&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;myproject
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Django 프로젝트의 기본 구조를 생성합니다. 프로젝트는 사이트의 전체 응용 프로그램을 포함합니다.&lt;code&gt;django-admin&lt;/code&gt; 명령어를 사용해 새 프로젝트를 생성합니다. 이 명령어는 Django 프로젝트의 기본 폴더 구조와 파일을 설정합니다.&lt;/p&gt;
&lt;h4&gt;애플리케이션 생성&lt;/h4&gt;
&lt;p&gt;Django 프로젝트 내에서, 특정 기능을 담당하는 애플리케이션을 생성할 수 있습니다.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;python&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;manage.py&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;startapp&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;myapp
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Django에서 애플리케이션은 프로젝트의 구성 요소로, 일련의 기능을 그룹화합니다. &lt;code&gt;manage.py&lt;/code&gt; 스크립트와 &lt;code&gt;startapp&lt;/code&gt; 명령어를 사용하여 새 애플리케이션을 생성합니다.&lt;/p&gt;
&lt;h4&gt;모델 정의&lt;/h4&gt;
&lt;p&gt;&lt;code&gt;myapp/models.py&lt;/code&gt; 파일을 열고 간단한 모델을 정의합니다. 예를 들어, 간단한 &lt;code&gt;Post&lt;/code&gt; 모델을 만들어봅시다.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;django.db&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;models&lt;/span&gt;

   &lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Post&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Model&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
       &lt;span class=&quot;n&quot;&gt;title&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;CharField&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;max_length&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
       &lt;span class=&quot;n&quot;&gt;content&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;models&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;TextField&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;

       &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;fm&quot;&gt;__str__&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
           &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;title&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;여기서는 데이터베이스 구조를 정의합니다. Django에서 모델은 데이터베이스의 테이블에 해당하며, 각 필드는 테이블의 컬럼입니다.
  &lt;code&gt;models.py&lt;/code&gt; 파일에 클래스로 모델을 정의합니다. 이 클래스는 &lt;code&gt;django.db.models.Model&lt;/code&gt;을 상속받아 Django ORM을 통해 데이터베이스와 상호작용합니다.&lt;/p&gt;
&lt;h4&gt;모델을 Admin 사이트에 등록&lt;/h4&gt;
&lt;p&gt;&lt;code&gt;myapp/admin.py&lt;/code&gt; 파일을 열고 &lt;code&gt;Post&lt;/code&gt; 모델을 등록합니다.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;django.contrib&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;admin&lt;/span&gt;
  &lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;.models&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Post&lt;/span&gt;

  &lt;span class=&quot;n&quot;&gt;admin&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;site&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;register&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Post&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;생성한 모델을 Django의 관리자 사이트에서 관리할 수 있도록 합니다.
  &lt;code&gt;admin.py&lt;/code&gt; 파일에 모델을 등록합니다. 이렇게 하면 Django의 관리자 인터페이스에서 모델을 추가, 수정, 삭제할 수 있습니다.&lt;/p&gt;
&lt;h4&gt;데이터베이스 마이그레이션&lt;/h4&gt;
&lt;p&gt;모델 변경 사항을 데이터베이스에 적용하기 위해 마이그레이션을 실행합니다.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;python&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;manage.py&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;makemigrations
&lt;span class=&quot;w&quot;&gt;  &lt;/span&gt;python&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;manage.py&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;migrate
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;모델의 변경사항을 데이터베이스에 적용합니다.
  &lt;code&gt;makemigrations&lt;/code&gt; 명령어로 모델 변경 사항에 대한 마이그레이션 파일을 생성하고, &lt;code&gt;migrate&lt;/code&gt; 명령어로 이를 데이터베이스에 적용합니다.&lt;/p&gt;
&lt;h4&gt;개발 서버 실행&lt;/h4&gt;
&lt;p&gt;Django의 내장 개발 서버를 실행합니다.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;python&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;manage.py&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;runserver
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;이제 브라우저에서 &lt;code&gt;http://127.0.0.1:8000/&lt;/code&gt;로 접속하면 Django 개발 서버가 실행 중인 것을 볼 수 있습니다.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;runserver&lt;/code&gt; 명령어를 사용하여 개발 서버를 시작합니다. 이 서버는 개발 중에 애플리케이션을 테스트하기 위한 것입니다&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiL6mTZIn92cIHIB4lZZz8lynmeOr_kUM40xdQe_NcHgY-eIzxKHsQoDJh1pk35KE8OKsLjC8v7zGIoTCr1R1huAPfy5dQLIooSpUhq-PwXrl6bbmCooB-lUc_e0sQmIGUKU6F66fNxBI3M4OW-8CFba-iobJTsXZuJlnzKbhG7eTM4mWtj3zd4Gy_DGieb/s913/django.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em; text-align: center;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;517&quot; data-original-width=&quot;913&quot; height=&quot;227&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiL6mTZIn92cIHIB4lZZz8lynmeOr_kUM40xdQe_NcHgY-eIzxKHsQoDJh1pk35KE8OKsLjC8v7zGIoTCr1R1huAPfy5dQLIooSpUhq-PwXrl6bbmCooB-lUc_e0sQmIGUKU6F66fNxBI3M4OW-8CFba-iobJTsXZuJlnzKbhG7eTM4mWtj3zd4Gy_DGieb/w400-h227/django.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;Admin 사이트 접속&lt;/h4&gt;
&lt;p&gt;Django는 기본적으로 관리자 사이트를 제공합니다. 관리자 계정을 만들어 접속해봅시다.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;python&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;manage.py&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;createsuperuser
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;관리자 계정을 만든 후, &lt;code&gt;http://127.0.0.1:8000/admin&lt;/code&gt;로 접속하여 로그인할 수 있습니다. 여기서 &lt;code&gt;Post&lt;/code&gt; 모델을 관리할 수 있습니다.&lt;/p&gt;
&lt;p&gt;이러한 단계를 통해 기본적인 Django 프로젝트를 설정하고, 간단한 모델을 만들어 Admin 사이트에서 관리할 수 있게 되었습니다. Django는 이보다 훨씬 다양하고 복잡한 기능을 제공하므로, 웹 애플리케이션의 요구사항에 맞게 추가적인 개발을 진행할 수 있습니다.&lt;/p&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://pyengine.blogspot.com/feeds/2251284720120640421/comments/default' title='댓글'/><link rel='replies' type='text/html' href='http://pyengine.blogspot.com/2023/12/python-django-quick-start.html#comment-form' title='0개의 덧글'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4881868893095669586/posts/default/2251284720120640421'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4881868893095669586/posts/default/2251284720120640421'/><link rel='alternate' type='text/html' href='http://pyengine.blogspot.com/2023/12/python-django-quick-start.html' title='Python Django Quick-start'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiL6mTZIn92cIHIB4lZZz8lynmeOr_kUM40xdQe_NcHgY-eIzxKHsQoDJh1pk35KE8OKsLjC8v7zGIoTCr1R1huAPfy5dQLIooSpUhq-PwXrl6bbmCooB-lUc_e0sQmIGUKU6F66fNxBI3M4OW-8CFba-iobJTsXZuJlnzKbhG7eTM4mWtj3zd4Gy_DGieb/s72-w400-h227-c/django.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4881868893095669586.post-2517094198666684573</id><published>2023-12-02T00:00:00.001+09:00</published><updated>2023-12-02T06:59:47.270+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="python"/><category scheme="http://www.blogger.com/atom/ns#" term="pytorch"/><category scheme="http://www.blogger.com/atom/ns#" term="예제"/><title type='text'>Pytorch 설치 및 간단한 예제</title><content type='html'>&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h1&gt;Pytorch 설치 및 간단한 예제&lt;/h1&gt;
&lt;p&gt;PyTorch는 딥 러닝 모델을 구축하고 학습하기 위한 인기 있는 라이브러리입니다. 여기 간단한 PyTorch 예제를 테스트 해봅니다. 이 예제에서는 기본적인 신경망을 구성하고, 간단한 데이터셋에 대해 이 신경망을 학습시키는 과정을 보여줍니다.&lt;/p&gt;
&lt;h3&gt;예제: 기본적인 신경망 학습&lt;/h3&gt;
&lt;h4&gt;1. 필요한 라이브러리 임포트&lt;/h4&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;torch&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;torch.nn&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;nn&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;torch.optim&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;optim&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;여기서는 PyTorch 관련 주요 라이브러리를 임포트합니다.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;torch&lt;/code&gt;: PyTorch의 기본 모듈로, 텐서 연산 및 기타 기본 기능을 제공합니다.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;torch.nn&lt;/code&gt;: 신경망을 구축하는 데 필요한 모듈 및 클래스를 제공합니다.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;torch.optim&lt;/code&gt;: 최적화 알고리즘(예: SGD, Adam)을 포함하고 있으며, 이를 통해 모델의 가중치를 업데이트합니다.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;2. 신경망 모델 정의&lt;/h4&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Net&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;nn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Module&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;fm&quot;&gt;__init__&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;nb&quot;&gt;super&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Net&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;fm&quot;&gt;__init__&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;# 입력층, 은닉층, 출력층 정의&lt;/span&gt;
        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fc1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;nn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Linear&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;# 3개 입력 노드에서 3개 은닉 노드로&lt;/span&gt;
        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fc2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;nn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Linear&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;# 3개 은닉 노드에서 1개 출력 노드로&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;forward&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;torch&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;relu&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fc1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;# ReLU 활성화 함수 적용&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fc2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;# 모델 인스턴스 생성&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;net&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Net&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;사용자 정의 신경망 모델을 정의합니다. &lt;code&gt;nn.Module&lt;/code&gt;을 상속받아서 모델을 정의하며, &lt;code&gt;__init__&lt;/code&gt; 메서드에서 모델의 레이어를 정의하고 &lt;code&gt;forward&lt;/code&gt; 메서드에서 데이터가 모델을 통과할 때 수행할 계산을 정의합니다.&lt;/p&gt;
&lt;h4&gt;3. 손실 함수와 최적화 기법 선택&lt;/h4&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;criterion&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;nn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;MSELoss&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;# 평균 제곱 오차 손실 함수&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;optimizer&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;optim&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;SGD&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;net&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;parameters&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lr&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.01&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;# 확률적 경사 하강법 최적화&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;criterion&lt;/code&gt;: 모델의 출력과 실제 타겟 간의 차이를 계산하는 손실 함수를 정의합니다. 여기서는 평균 제곱 오차(MSE)를 사용합니다.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;optimizer&lt;/code&gt;: 모델의 가중치를 업데이트하는 방법을 정의합니다. 여기서는 확률적 경사 하강법(SGD)과 학습률(Learning rate) 0.01을 사용합니다.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;4. 학습 데이터 준비&lt;/h4&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class=&quot;c1&quot;&gt;# 간단한 예시 데이터셋&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;inputs&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;torch&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;tensor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([[&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;2.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;3.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;2.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;3.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;2.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;3.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]])&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;targets&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;torch&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;tensor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([[&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;2.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;3.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]])&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;이 단계에서는 학습에 사용할 입력 데이터(&lt;code&gt;inputs&lt;/code&gt;)와 해당 타겟 레이블(&lt;code&gt;targets&lt;/code&gt;)을 정의합니다. 이 데이터는 모델을 훈련시키는 데 사용됩니다.&lt;/p&gt;
&lt;h4&gt;5. 학습 과정&lt;/h4&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;epoch&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;500&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;# 에포크 수 설정&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;optimizer&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;zero_grad&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;   &lt;span class=&quot;c1&quot;&gt;# 그래디언트 버퍼 초기화&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;outputs&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;net&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;inputs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;   &lt;span class=&quot;c1&quot;&gt;# 입력에 대한 예측값 계산&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;loss&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;criterion&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;outputs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;targets&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;# 손실 계산&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;loss&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;backward&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;# 역전파 수행&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;optimizer&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;step&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;# 가중치 업데이트&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;epoch&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;%&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;50&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;# 매 50 에포크마다 손실 출력&lt;/span&gt;
        &lt;span class=&quot;nb&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;Epoch [&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;epoch&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;/500], Loss: &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;loss&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;.4f&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;이 부분은 모델을 학습시키는 과정입니다. 각 에포크마다 다음의 단계를 수행합니다:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;optimizer.zero_grad()&lt;/code&gt;: 이전 에포크에서 계산된 그래디언트를 초기화합니다.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;outputs = net(inputs)&lt;/code&gt;: 현재 모델을 사용하여 입력 데이터에 대한 예측을 수행합니다.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;loss = criterion(outputs, targets)&lt;/code&gt;: 손실 함수를 사용하여 예측과 실제 타겟 간의 손실을 계산합니다.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;loss.backward()&lt;/code&gt;: 손실에 대한 그래디언트를 계산하기 위해 역전파를 수행합니다.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;optimizer.step()&lt;/code&gt;: 계산된 그래디언트를 사용하여 모델의 가중치를 업데이트합니다.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;추가로 에포크(epoch)의 의미는 머신 러닝, 특히 신경망 학습에서 전체 학습 데이터셋이 모델을 통과하는 한 번의 완전한 사이클을 의미합니다. 각 에포크에서 모델은 데이터셋의 모든 샘플을 한 번씩 처리하고, 이를 통해 가중치를 업데이트합니다. 모델의 성능을 향상시키기 위해 여러 에포크를 거치며 학습을 반복합니다.&lt;/p&gt;
&lt;p&gt;이 예제는 PyTorch를 사용하여 간단한 신경망을 구성하고, 작은 데이터셋에 대해 신경망을 학습시키는 기본적인 프로세스를 보여줍니다. 실제로 복잡한 데이터셋과 문제에 적용할 때는 더 많은 레이어, 다양한 데이터 전처리 방법, 복잡한 최적화 알고리즘 등이 사용될 수 있습니다.&lt;/p&gt;
</content><link rel='replies' type='application/atom+xml' href='http://pyengine.blogspot.com/feeds/2517094198666684573/comments/default' title='댓글'/><link rel='replies' type='text/html' href='http://pyengine.blogspot.com/2023/12/pytorch.html#comment-form' title='0개의 덧글'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4881868893095669586/posts/default/2517094198666684573'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4881868893095669586/posts/default/2517094198666684573'/><link rel='alternate' type='text/html' href='http://pyengine.blogspot.com/2023/12/pytorch.html' title='Pytorch 설치 및 간단한 예제'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4881868893095669586.post-7132044564899251273</id><published>2023-10-15T09:16:00.002+09:00</published><updated>2023-10-15T09:16:41.443+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="chatgpt"/><category scheme="http://www.blogger.com/atom/ns#" term="dalle3"/><title type='text'>Chat GPT4 + DALL.E 3</title><content type='html'>&lt;p&gt;몇일전에 CHAT-GPT4 에 DALL-E3 가 integration되었다 (유로 사용자대상인듯)&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhGw3YL9ggbyhL0BltqFS4T5GiCGf9tAqTRsAcjsmH1GiD8v0X-095VpzujgmcvZ76o9SbCts0ySu247Hi623uYkdo_hO_JCzkJ91F82SRWl7AeiZfyKBwiBLLxOgKqX8PWdjN-VVCykKcmPwiCw75_hvp6uLh1W96l1VaZtdMNmfNO7AjT6_N9Wcp9C3Ys/s601/%EC%8A%A4%ED%81%AC%EB%A6%B0%EC%83%B7%202023-10-15%20090621.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;601&quot; data-original-width=&quot;515&quot; height=&quot;430&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhGw3YL9ggbyhL0BltqFS4T5GiCGf9tAqTRsAcjsmH1GiD8v0X-095VpzujgmcvZ76o9SbCts0ySu247Hi623uYkdo_hO_JCzkJ91F82SRWl7AeiZfyKBwiBLLxOgKqX8PWdjN-VVCykKcmPwiCw75_hvp6uLh1W96l1VaZtdMNmfNO7AjT6_N9Wcp9C3Ys/w369-h430/%EC%8A%A4%ED%81%AC%EB%A6%B0%EC%83%B7%202023-10-15%20090621.png&quot; width=&quot;369&quot; /&gt;&lt;/a&gt;&lt;/div&gt;이제 그림까지 그려주는 중,&amp;nbsp;&lt;p&gt;&lt;/p&gt;&lt;p&gt;나무 괴물을 그려달라고 했더니, 아래와 같이 그려줌,&amp;nbsp;&lt;/p&gt;&lt;p&gt;별도의 프롬프트도 같이 제공한다. 간단한 말을 GPT가 디테일하게 설명을 만들고 DALL.E가 그림을 그리는 형태인듯하다.&amp;nbsp;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiew1NS9Temsj0RAm0oLdWRrR3Y3e697zgAVDRnnbRkzK2J35FOChNy4l2GPpsdTt6x-lEoDW2TmgDfck1yxqgabKtzvqFkk8iboMyMi1BCeosNSD0qaTC0_8Wur8JDKk03bRdTG8E7ZWsJASyDPL0l75cmBE5AFnz_tyHXjnUixEQzJnyQu9QrPDawYLY0/s1024/tree%20monster.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;1024&quot; data-original-width=&quot;1024&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiew1NS9Temsj0RAm0oLdWRrR3Y3e697zgAVDRnnbRkzK2J35FOChNy4l2GPpsdTt6x-lEoDW2TmgDfck1yxqgabKtzvqFkk8iboMyMi1BCeosNSD0qaTC0_8Wur8JDKk03bRdTG8E7ZWsJASyDPL0l75cmBE5AFnz_tyHXjnUixEQzJnyQu9QrPDawYLY0/s320/tree%20monster.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;p&gt;앞으로 어떻게 될지 더 기대가 되는 상황으로 보인다.&amp;nbsp;&lt;/p&gt;&lt;p&gt;저작권등은 어떻게 될지도 궁금하다. 이제는 어떤게 진짜인지 어떤게 가짜인지 분간을 하지 못하는 세상이 될것이고 어떤게 원본인지 구분하기도 쉽지 않을 듯 하다.&amp;nbsp;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://pyengine.blogspot.com/feeds/7132044564899251273/comments/default' title='댓글'/><link rel='replies' type='text/html' href='http://pyengine.blogspot.com/2023/10/chat-gpt4-dalle-3.html#comment-form' title='0개의 덧글'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4881868893095669586/posts/default/7132044564899251273'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4881868893095669586/posts/default/7132044564899251273'/><link rel='alternate' type='text/html' href='http://pyengine.blogspot.com/2023/10/chat-gpt4-dalle-3.html' title='Chat GPT4 + DALL.E 3'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhGw3YL9ggbyhL0BltqFS4T5GiCGf9tAqTRsAcjsmH1GiD8v0X-095VpzujgmcvZ76o9SbCts0ySu247Hi623uYkdo_hO_JCzkJ91F82SRWl7AeiZfyKBwiBLLxOgKqX8PWdjN-VVCykKcmPwiCw75_hvp6uLh1W96l1VaZtdMNmfNO7AjT6_N9Wcp9C3Ys/s72-w369-h430-c/%EC%8A%A4%ED%81%AC%EB%A6%B0%EC%83%B7%202023-10-15%20090621.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4881868893095669586.post-64267170296628749</id><published>2023-10-10T00:00:00.001+09:00</published><updated>2023-10-10T04:29:00.043+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="openai"/><category scheme="http://www.blogger.com/atom/ns#" term="python"/><category scheme="http://www.blogger.com/atom/ns#" term="pytube"/><category scheme="http://www.blogger.com/atom/ns#" term="whisper"/><title type='text'>Python whisper open AI</title><content type='html'>&lt;p&gt;Whisper는 OpenAI에서 공개한 STT(Speech to Text) 이다&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;이게 용도가 여러가지 있겠지만, 영어 공부나 자막만들기, 스크립트 만들기, 회의록을 작성한다던가&amp;nbsp;할때 유용하다.&amp;nbsp;&lt;/p&gt;&lt;p&gt;특히 언어를 배울때 특히, 영어 공부하는 용도로 굉장히 유용할 듯하다.&amp;nbsp;&lt;br /&gt;요즘 게다가 AI 번역기들이 성능이 어마 무시하기때문에 여기에 연동을 시키면,&amp;nbsp;&lt;/p&gt;&lt;p&gt;언어적 장벽없이 이것저것을 할 수 있을 정도가 될듯하다.&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;보통 영어 뉴스 듣기 이런거를 하다가 막히는 게 뭐냐하면, 제대로 된 스크립트를 얻을 수가 없다는데 있다. 그래서, 이미 스크립트가 있는 경우는 쉽게 하지만, 최신 뉴스들에서는 어려운 점이 있는데, 이 Whisper를 사용하면 최신 뉴스에 대해서도 스크립트를 얻을 수 있기 때문에 굉장히 유용한점이 있다.&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;유튜브에서 다운받기&lt;/b&gt;&lt;/p&gt;&lt;p&gt;유튜브에서 파이썬으로 파일 내려 받는 방법은 다음과 같다.&amp;nbsp;&lt;/p&gt;&lt;p&gt;먼저 pytube를 설치한다.&amp;nbsp;&lt;/p&gt;
&lt;br /&gt;
&lt;pre class=&quot;prettyprint lang-bash&quot;&gt;&lt;code&gt;pip install pytube
&lt;/code&gt;
&lt;/pre&gt;



&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;그 다음에 아래와 같이 아래와 같이 수행할 경우, mp4 audio 형태로 다운을 받을 수가 있다.&amp;nbsp;&lt;/p&gt;

&lt;pre class=&quot;prettyprint&quot;&gt;
import pytube

video = &quot;https://www.youtube.com/watch?v=[유튜브 주소]&quot;
data = pytube.YouTube(video)
# Converting and downloading as &#39;MP4&#39; file
audio = data.streams.get_audio_only()
audio.download()
&lt;/pre&gt;

&lt;br /&gt;
&lt;p&gt;다음은 whisper를 설치한다. &lt;/p&gt;

&lt;pre class=&quot;prettyprint&quot;&gt;
pip install -U openai-whisper
&lt;/pre&gt;


&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;이상태에서 whisper로 내려받은 mp4 파일을 text로 변환하면 된다. 영어는 거의 상당히 정확하게 text를 뽑아주니, 이를 잘 활용하면 유용할듯하다.다음은 whisper로 변환를하는 예제이다.  &amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;
import whisper

model = whisper.load_model(&quot;base&quot;)
fname = &quot;파일이름&quot;
text = model.transcribe(f&quot;{fname}.mp4&quot;)

with open(f&#39;{fname}.txt&#39;,&#39;w&#39;) as wf:
  print (text[&#39;text&#39;],file=wf)
&lt;/pre&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;다만 whisper runtime은 바로 나오지는 않고 시간이 많이 소모되기는 하다.&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://pyengine.blogspot.com/feeds/64267170296628749/comments/default' title='댓글'/><link rel='replies' type='text/html' href='http://pyengine.blogspot.com/2023/10/python-whisper-open-ai.html#comment-form' title='0개의 덧글'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4881868893095669586/posts/default/64267170296628749'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4881868893095669586/posts/default/64267170296628749'/><link rel='alternate' type='text/html' href='http://pyengine.blogspot.com/2023/10/python-whisper-open-ai.html' title='Python whisper open AI'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4881868893095669586.post-1965790544464406298</id><published>2023-09-23T15:15:00.001+09:00</published><updated>2023-09-23T15:15:00.135+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="c++"/><category scheme="http://www.blogger.com/atom/ns#" term="pybind"/><category scheme="http://www.blogger.com/atom/ns#" term="python"/><title type='text'>python pybind 11 c++ 과 연결하기</title><content type='html'>pybind 라는 패키지가 있다.&lt;br /&gt;
&lt;br /&gt;
c++과 연결하는 것인데, header only library이고,&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;아래 페이지가 해당 사이트이다.&amp;nbsp;&lt;/div&gt;&lt;div&gt;https://github.com/pybind/pybind11&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;기존에는 ctype등을 이용해서 주로 python과 C를 연결했었는데,&amp;nbsp;&lt;/div&gt;&lt;div&gt;이것은 C++과 다이렉트로 연결해주는 패키지이다.&amp;nbsp;&lt;/div&gt;&lt;div&gt;이전에도 C++은 python과 바로 연결은 안되고, extern이라든지 c형태로 함수를 다시 재구성해서 노출시키는 방법들을 사용했었는데, 이것은 간단한 작성으로 이런것들을 가능하게 해주는듯하다.&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;이전에 Boost.Python이 그런역할을 해주는데, 부스트라는게 사실 좀 헤비한 면이 없지 않은지라 header only에 standard c++만 사용한 이 패키지도 나쁘지는 않은듯하다.&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;p class=&quot;code-line&quot; data-line=&quot;4&quot; dir=&quot;auto&quot; style=&quot;color: #3b3b3b; font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Segoe WPC&amp;quot;, &amp;quot;Segoe UI&amp;quot;, system-ui, Ubuntu, &amp;quot;Droid Sans&amp;quot;, sans-serif; font-size: 14px; margin-bottom: 16px; margin-top: 0px; position: relative;&quot;&gt;먼저 pybind설치&lt;/p&gt;&lt;pre style=&quot;border-radius: 3px; border: 1px solid var(--vscode-widget-border); color: #3b3b3b; font-size: 14px; margin-top: 0px; overflow: auto; padding: 16px; text-wrap: wrap;&quot;&gt;&lt;code class=&quot;code-line language-bash&quot; data-line=&quot;6&quot; dir=&quot;auto&quot; style=&quot;color: var(--vscode-editor-foreground); font-family: var(--vscode-editor-font-family, &amp;quot;SF Mono&amp;quot;, Monaco, Menlo, Consolas, &amp;quot;Ubuntu Mono&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace); font-size: 1em; line-height: 1.357em; position: relative; tab-size: 4;&quot;&gt;&amp;gt;&amp;gt; pip install pybind11 
&lt;/code&gt;&lt;/pre&gt;&lt;p class=&quot;code-line&quot; data-line=&quot;11&quot; dir=&quot;auto&quot; style=&quot;color: #3b3b3b; font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Segoe WPC&amp;quot;, &amp;quot;Segoe UI&amp;quot;, system-ui, Ubuntu, &amp;quot;Droid Sans&amp;quot;, sans-serif; font-size: 14px; margin-bottom: 16px; margin-top: 0px; position: relative;&quot;&gt;아래와 같이 c-code를 작성한다. example.cpp&lt;/p&gt;&lt;pre style=&quot;border-radius: 3px; border: 1px solid var(--vscode-widget-border); color: #3b3b3b; font-size: 14px; margin-top: 0px; overflow: auto; padding: 16px; text-wrap: wrap;&quot;&gt;&lt;code class=&quot;code-line language-c&quot; data-line=&quot;14&quot; dir=&quot;auto&quot; style=&quot;color: var(--vscode-editor-foreground); font-family: var(--vscode-editor-font-family, &amp;quot;SF Mono&amp;quot;, Monaco, Menlo, Consolas, &amp;quot;Ubuntu Mono&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace); font-size: 1em; line-height: 1.357em; position: relative; tab-size: 4;&quot;&gt;&lt;span class=&quot;hljs-meta&quot; style=&quot;color: #2b91af;&quot;&gt;#&lt;span class=&quot;hljs-keyword&quot; style=&quot;color: blue;&quot;&gt;include&lt;/span&gt; &lt;span class=&quot;hljs-string&quot; style=&quot;color: #a31515;&quot;&gt;&amp;lt;pybind11/pybind11.h&amp;gt;&lt;/span&gt;&lt;/span&gt;

&lt;span class=&quot;hljs-type&quot; style=&quot;color: #a31515;&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;hljs-title function_&quot; style=&quot;color: grey;&quot;&gt;add&lt;/span&gt;&lt;span class=&quot;hljs-params&quot; style=&quot;color: inherit;&quot;&gt;(&lt;span class=&quot;hljs-type&quot; style=&quot;color: #a31515;&quot;&gt;int&lt;/span&gt; i, &lt;span class=&quot;hljs-type&quot; style=&quot;color: #a31515;&quot;&gt;int&lt;/span&gt; j)&lt;/span&gt; {
    &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; i + j;
}

namespace py = pybind11;

PYBIND11_MODULE(example, m) {
    m.doc() = &lt;span class=&quot;hljs-string&quot; style=&quot;color: #a31515;&quot;&gt;&quot;pybind11 example plugin&quot;&lt;/span&gt;; &lt;span class=&quot;hljs-comment&quot; style=&quot;color: green; font-style: italic;&quot;&gt;// 모듈 독스트링 설정&lt;/span&gt;

    m.def(&lt;span class=&quot;hljs-string&quot; style=&quot;color: #a31515;&quot;&gt;&quot;add&quot;&lt;/span&gt;, &amp;amp;add, &lt;span class=&quot;hljs-string&quot; style=&quot;color: #a31515;&quot;&gt;&quot;A function which adds two numbers&quot;&lt;/span&gt;); &lt;span class=&quot;hljs-comment&quot; style=&quot;color: green; font-style: italic;&quot;&gt;// 함수 바인딩&lt;/span&gt;
}
&lt;/code&gt;&lt;/pre&gt;&lt;p class=&quot;code-line&quot; data-line=&quot;28&quot; dir=&quot;auto&quot; style=&quot;color: #3b3b3b; font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Segoe WPC&amp;quot;, &amp;quot;Segoe UI&amp;quot;, system-ui, Ubuntu, &amp;quot;Droid Sans&amp;quot;, sans-serif; font-size: 14px; margin-bottom: 16px; margin-top: 0px; position: relative;&quot;&gt;이것을 다음과 같이 컴파일 header-only이기때문에&amp;nbsp;&lt;code style=&quot;color: var(--vscode-textPreformat-foreground); font-family: var(--vscode-editor-font-family, &amp;quot;SF Mono&amp;quot;, Monaco, Menlo, Consolas, &amp;quot;Ubuntu Mono&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace); font-size: 1em; line-height: 1.357em;&quot;&gt;python3 -m pybind11 --includes&lt;/code&gt;&amp;nbsp;이 명령어를 통해서 관련 헤더가 추가된다.&lt;/p&gt;&lt;pre style=&quot;border-radius: 3px; border: 1px solid var(--vscode-widget-border); color: #3b3b3b; font-size: 14px; margin-top: 0px; overflow: auto; padding: 16px; text-wrap: wrap;&quot;&gt;&lt;code class=&quot;code-line language-bash&quot; data-line=&quot;33&quot; dir=&quot;auto&quot; style=&quot;color: var(--vscode-editor-foreground); font-family: var(--vscode-editor-font-family, &amp;quot;SF Mono&amp;quot;, Monaco, Menlo, Consolas, &amp;quot;Ubuntu Mono&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace); font-size: 1em; line-height: 1.357em; position: relative; tab-size: 4;&quot;&gt;
c++ -O3 -Wall -shared -std=c++11 -fPIC `python3 -m pybind11 --includes` example.cpp -o example`python3-config --extension-suffix`
&lt;/code&gt;&lt;/pre&gt;&lt;p class=&quot;code-line&quot; data-line=&quot;36&quot; dir=&quot;auto&quot; style=&quot;color: #3b3b3b; font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Segoe WPC&amp;quot;, &amp;quot;Segoe UI&amp;quot;, system-ui, Ubuntu, &amp;quot;Droid Sans&amp;quot;, sans-serif; font-size: 14px; margin-bottom: 16px; margin-top: 0px; position: relative;&quot;&gt;아래와 같이 python 에서 불러들이면 끝&lt;/p&gt;&lt;pre style=&quot;border-radius: 3px; border: 1px solid var(--vscode-widget-border); color: #3b3b3b; font-size: 14px; margin-top: 0px; overflow: auto; padding: 16px; text-wrap: wrap;&quot;&gt;&lt;code class=&quot;code-line language-py&quot; data-line=&quot;40&quot; dir=&quot;auto&quot; style=&quot;color: var(--vscode-editor-foreground); font-family: var(--vscode-editor-font-family, &amp;quot;SF Mono&amp;quot;, Monaco, Menlo, Consolas, &amp;quot;Ubuntu Mono&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace); font-size: 1em; line-height: 1.357em; position: relative; tab-size: 4;&quot;&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;color: blue;&quot;&gt;import&lt;/span&gt; example

result = example.add(&lt;span class=&quot;hljs-number&quot; style=&quot;color: green;&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot; style=&quot;color: green;&quot;&gt;2&lt;/span&gt;)
&lt;span class=&quot;hljs-built_in&quot; style=&quot;color: #007acc;&quot;&gt;print&lt;/span&gt;(result)  
&lt;span class=&quot;hljs-comment&quot; style=&quot;color: green; font-style: italic;&quot;&gt;# 출력: 3&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;p class=&quot;code-line&quot; data-line=&quot;45&quot; dir=&quot;auto&quot; style=&quot;color: #3b3b3b; font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Segoe WPC&amp;quot;, &amp;quot;Segoe UI&amp;quot;, system-ui, Ubuntu, &amp;quot;Droid Sans&amp;quot;, sans-serif; font-size: 14px; margin-bottom: 16px; margin-top: 0px; position: relative;&quot;&gt;위와 같이 간단하게 python에서 c-code를 실행시키는 코드를 만들수 있다.&lt;/p&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pyengine.blogspot.com/feeds/1965790544464406298/comments/default' title='댓글'/><link rel='replies' type='text/html' href='http://pyengine.blogspot.com/2020/01/python-pybind-11-c.html#comment-form' title='0개의 덧글'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4881868893095669586/posts/default/1965790544464406298'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4881868893095669586/posts/default/1965790544464406298'/><link rel='alternate' type='text/html' href='http://pyengine.blogspot.com/2020/01/python-pybind-11-c.html' title='python pybind 11 c++ 과 연결하기'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4881868893095669586.post-6167057356440908960</id><published>2023-09-08T00:30:00.000+09:00</published><updated>2023-09-08T00:30:00.148+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="arange"/><category scheme="http://www.blogger.com/atom/ns#" term="array"/><category scheme="http://www.blogger.com/atom/ns#" term="empty"/><category scheme="http://www.blogger.com/atom/ns#" term="eye"/><category scheme="http://www.blogger.com/atom/ns#" term="linspace"/><category scheme="http://www.blogger.com/atom/ns#" term="logspace"/><category scheme="http://www.blogger.com/atom/ns#" term="numpy"/><category scheme="http://www.blogger.com/atom/ns#" term="ones"/><category scheme="http://www.blogger.com/atom/ns#" term="zeros"/><title type='text'>NumPy Array 생성 함수</title><content type='html'>&lt;p&gt;&amp;nbsp;&lt;span style=&quot;color: #3b3b3b; font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Segoe WPC&amp;quot;, &amp;quot;Segoe UI&amp;quot;, system-ui, Ubuntu, &amp;quot;Droid Sans&amp;quot;, sans-serif; font-size: 14px;&quot;&gt;NumPy에서는 다양한 방법으로 배열을 생성할 수 있는 함수들을 제공합니다. 이러한 함수들에 대해서 정리해보았슨비다.&lt;/span&gt;&lt;/p&gt;&lt;h2 class=&quot;code-line&quot; data-line=&quot;729&quot; dir=&quot;auto&quot; id=&quot;numpy-array-%EC%83%9D%EC%84%B1-%ED%95%A8%EC%88%98&quot; style=&quot;border-bottom: 1px solid rgba(0, 0, 0, 0.18); border-left-color: rgba(0, 0, 0, 0.18); border-right-color: rgba(0, 0, 0, 0.18); border-top-color: rgba(0, 0, 0, 0.18); color: #3b3b3b; font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Segoe WPC&amp;quot;, &amp;quot;Segoe UI&amp;quot;, system-ui, Ubuntu, &amp;quot;Droid Sans&amp;quot;, sans-serif; line-height: 1.25; margin-bottom: 16px; margin-top: 24px; padding-bottom: 0.3em; position: relative;&quot;&gt;NumPy Array 생성 함수&lt;/h2&gt;&lt;table class=&quot;code-line&quot; data-line=&quot;731&quot; dir=&quot;auto&quot; style=&quot;border-collapse: collapse; border-radius: 0.2rem; border-spacing: 0px; box-shadow: rgba(0, 0, 0, 0.05) 0px 0.2rem 0.5rem, rgba(0, 0, 0, 0.1) 0px 0px 0.0625rem; color: #3b3b3b; font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Segoe WPC&amp;quot;, &amp;quot;Segoe UI&amp;quot;, system-ui, Ubuntu, &amp;quot;Droid Sans&amp;quot;, sans-serif; font-size: 14px; margin-bottom: 0.7em; position: relative;&quot;&gt;&lt;thead class=&quot;code-line&quot; data-line=&quot;731&quot; dir=&quot;auto&quot; style=&quot;position: relative;&quot;&gt;&lt;tr class=&quot;code-line&quot; data-line=&quot;731&quot; dir=&quot;auto&quot; style=&quot;position: relative;&quot;&gt;&lt;th style=&quot;border-bottom-color: rgba(0, 0, 0, 0.69); border-left: none; border-right-color: rgba(0, 0, 0, 0.69); border-top-color: rgba(0, 0, 0, 0.69); color: var(--color-foreground-primary); padding: 0px 0.25rem; text-align: left;&quot;&gt;함수&lt;/th&gt;&lt;th style=&quot;border-color: rgba(0, 0, 0, 0.69); color: var(--color-foreground-primary); padding: 0px 0.25rem; text-align: left;&quot;&gt;설명&lt;/th&gt;&lt;th style=&quot;border-color: rgba(0, 0, 0, 0.69); color: var(--color-foreground-primary); padding: 0px 0.25rem; text-align: left;&quot;&gt;예제&lt;/th&gt;&lt;th style=&quot;border-bottom-color: rgba(0, 0, 0, 0.69); border-left-color: rgba(0, 0, 0, 0.69); border-right: none; border-top-color: rgba(0, 0, 0, 0.69); color: var(--color-foreground-primary); padding: 0px 0.25rem; text-align: left;&quot;&gt;결과&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody class=&quot;code-line&quot; data-line=&quot;733&quot; dir=&quot;auto&quot; style=&quot;position: relative;&quot;&gt;&lt;tr class=&quot;code-line&quot; data-line=&quot;733&quot; dir=&quot;auto&quot; style=&quot;position: relative;&quot;&gt;&lt;td style=&quot;border-bottom-color: rgba(0, 0, 0, 0.18); border-left: none; border-right-color: rgba(0, 0, 0, 0.18); border-top-color: rgba(0, 0, 0, 0.18); padding: 0px 0.25rem;&quot;&gt;&lt;code style=&quot;color: var(--vscode-textPreformat-foreground); font-family: var(--vscode-editor-font-family, &amp;quot;SF Mono&amp;quot;, Monaco, Menlo, Consolas, &amp;quot;Ubuntu Mono&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace); font-size: 1em; line-height: 1.357em;&quot;&gt;np.array&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;border-color: rgba(0, 0, 0, 0.18); padding: 0px 0.25rem;&quot;&gt;주어진 데이터로부터 배열을 생성&lt;/td&gt;&lt;td style=&quot;border-color: rgba(0, 0, 0, 0.18); padding: 0px 0.25rem;&quot;&gt;&lt;code style=&quot;color: var(--vscode-textPreformat-foreground); font-family: var(--vscode-editor-font-family, &amp;quot;SF Mono&amp;quot;, Monaco, Menlo, Consolas, &amp;quot;Ubuntu Mono&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace); font-size: 1em; line-height: 1.357em;&quot;&gt;np.array([1, 2, 3])&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;border-bottom-color: rgba(0, 0, 0, 0.18); border-left-color: rgba(0, 0, 0, 0.18); border-right: none; border-top-color: rgba(0, 0, 0, 0.18); padding: 0px 0.25rem;&quot;&gt;&lt;code style=&quot;color: var(--vscode-textPreformat-foreground); font-family: var(--vscode-editor-font-family, &amp;quot;SF Mono&amp;quot;, Monaco, Menlo, Consolas, &amp;quot;Ubuntu Mono&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace); font-size: 1em; line-height: 1.357em;&quot;&gt;[1, 2, 3]&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr class=&quot;code-line&quot; data-line=&quot;734&quot; dir=&quot;auto&quot; style=&quot;position: relative;&quot;&gt;&lt;td style=&quot;border-bottom-color: rgba(0, 0, 0, 0.18); border-left: none; border-right-color: rgba(0, 0, 0, 0.18); border-top: 1px solid rgba(0, 0, 0, 0.18); padding: 0px 0.25rem;&quot;&gt;&lt;code style=&quot;color: var(--vscode-textPreformat-foreground); font-family: var(--vscode-editor-font-family, &amp;quot;SF Mono&amp;quot;, Monaco, Menlo, Consolas, &amp;quot;Ubuntu Mono&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace); font-size: 1em; line-height: 1.357em;&quot;&gt;np.zeros&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;border-color: rgba(0, 0, 0, 0.18); border-top-style: solid; border-top-width: 1px; padding: 0px 0.25rem;&quot;&gt;모든 원소가 0인 배열 생성&lt;/td&gt;&lt;td style=&quot;border-color: rgba(0, 0, 0, 0.18); border-top-style: solid; border-top-width: 1px; padding: 0px 0.25rem;&quot;&gt;&lt;code style=&quot;color: var(--vscode-textPreformat-foreground); font-family: var(--vscode-editor-font-family, &amp;quot;SF Mono&amp;quot;, Monaco, Menlo, Consolas, &amp;quot;Ubuntu Mono&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace); font-size: 1em; line-height: 1.357em;&quot;&gt;np.zeros((2, 3))&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;border-bottom-color: rgba(0, 0, 0, 0.18); border-left-color: rgba(0, 0, 0, 0.18); border-right: none; border-top: 1px solid rgba(0, 0, 0, 0.18); padding: 0px 0.25rem;&quot;&gt;&lt;code style=&quot;color: var(--vscode-textPreformat-foreground); font-family: var(--vscode-editor-font-family, &amp;quot;SF Mono&amp;quot;, Monaco, Menlo, Consolas, &amp;quot;Ubuntu Mono&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace); font-size: 1em; line-height: 1.357em;&quot;&gt;[[0., 0., 0.], [0., 0., 0.]]&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr class=&quot;code-line&quot; data-line=&quot;735&quot; dir=&quot;auto&quot; style=&quot;position: relative;&quot;&gt;&lt;td style=&quot;border-bottom-color: rgba(0, 0, 0, 0.18); border-left: none; border-right-color: rgba(0, 0, 0, 0.18); border-top: 1px solid rgba(0, 0, 0, 0.18); padding: 0px 0.25rem;&quot;&gt;&lt;code style=&quot;color: var(--vscode-textPreformat-foreground); font-family: var(--vscode-editor-font-family, &amp;quot;SF Mono&amp;quot;, Monaco, Menlo, Consolas, &amp;quot;Ubuntu Mono&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace); font-size: 1em; line-height: 1.357em;&quot;&gt;np.ones&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;border-color: rgba(0, 0, 0, 0.18); border-top-style: solid; border-top-width: 1px; padding: 0px 0.25rem;&quot;&gt;모든 원소가 1인 배열 생성&lt;/td&gt;&lt;td style=&quot;border-color: rgba(0, 0, 0, 0.18); border-top-style: solid; border-top-width: 1px; padding: 0px 0.25rem;&quot;&gt;&lt;code style=&quot;color: var(--vscode-textPreformat-foreground); font-family: var(--vscode-editor-font-family, &amp;quot;SF Mono&amp;quot;, Monaco, Menlo, Consolas, &amp;quot;Ubuntu Mono&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace); font-size: 1em; line-height: 1.357em;&quot;&gt;np.ones((3, 2))&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;border-bottom-color: rgba(0, 0, 0, 0.18); border-left-color: rgba(0, 0, 0, 0.18); border-right: none; border-top: 1px solid rgba(0, 0, 0, 0.18); padding: 0px 0.25rem;&quot;&gt;&lt;code style=&quot;color: var(--vscode-textPreformat-foreground); font-family: var(--vscode-editor-font-family, &amp;quot;SF Mono&amp;quot;, Monaco, Menlo, Consolas, &amp;quot;Ubuntu Mono&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace); font-size: 1em; line-height: 1.357em;&quot;&gt;[[1., 1.], [1., 1.], [1., 1.]]&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr class=&quot;code-line&quot; data-line=&quot;736&quot; dir=&quot;auto&quot; style=&quot;position: relative;&quot;&gt;&lt;td style=&quot;border-bottom-color: rgba(0, 0, 0, 0.18); border-left: none; border-right-color: rgba(0, 0, 0, 0.18); border-top: 1px solid rgba(0, 0, 0, 0.18); padding: 0px 0.25rem;&quot;&gt;&lt;code style=&quot;color: var(--vscode-textPreformat-foreground); font-family: var(--vscode-editor-font-family, &amp;quot;SF Mono&amp;quot;, Monaco, Menlo, Consolas, &amp;quot;Ubuntu Mono&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace); font-size: 1em; line-height: 1.357em;&quot;&gt;np.empty&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;border-color: rgba(0, 0, 0, 0.18); border-top-style: solid; border-top-width: 1px; padding: 0px 0.25rem;&quot;&gt;초기화되지 않은 배열 생성&lt;/td&gt;&lt;td style=&quot;border-color: rgba(0, 0, 0, 0.18); border-top-style: solid; border-top-width: 1px; padding: 0px 0.25rem;&quot;&gt;&lt;code style=&quot;color: var(--vscode-textPreformat-foreground); font-family: var(--vscode-editor-font-family, &amp;quot;SF Mono&amp;quot;, Monaco, Menlo, Consolas, &amp;quot;Ubuntu Mono&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace); font-size: 1em; line-height: 1.357em;&quot;&gt;np.empty((2, 2))&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;border-bottom-color: rgba(0, 0, 0, 0.18); border-left-color: rgba(0, 0, 0, 0.18); border-right: none; border-top: 1px solid rgba(0, 0, 0, 0.18); padding: 0px 0.25rem;&quot;&gt;랜덤 값&lt;/td&gt;&lt;/tr&gt;&lt;tr class=&quot;code-line&quot; data-line=&quot;737&quot; dir=&quot;auto&quot; style=&quot;position: relative;&quot;&gt;&lt;td style=&quot;border-bottom-color: rgba(0, 0, 0, 0.18); border-left: none; border-right-color: rgba(0, 0, 0, 0.18); border-top: 1px solid rgba(0, 0, 0, 0.18); padding: 0px 0.25rem;&quot;&gt;&lt;code style=&quot;color: var(--vscode-textPreformat-foreground); font-family: var(--vscode-editor-font-family, &amp;quot;SF Mono&amp;quot;, Monaco, Menlo, Consolas, &amp;quot;Ubuntu Mono&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace); font-size: 1em; line-height: 1.357em;&quot;&gt;np.arange&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;border-color: rgba(0, 0, 0, 0.18); border-top-style: solid; border-top-width: 1px; padding: 0px 0.25rem;&quot;&gt;주어진 범위와 간격의 배열 생성&lt;/td&gt;&lt;td style=&quot;border-color: rgba(0, 0, 0, 0.18); border-top-style: solid; border-top-width: 1px; padding: 0px 0.25rem;&quot;&gt;&lt;code style=&quot;color: var(--vscode-textPreformat-foreground); font-family: var(--vscode-editor-font-family, &amp;quot;SF Mono&amp;quot;, Monaco, Menlo, Consolas, &amp;quot;Ubuntu Mono&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace); font-size: 1em; line-height: 1.357em;&quot;&gt;np.arange(0, 10, 2)&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;border-bottom-color: rgba(0, 0, 0, 0.18); border-left-color: rgba(0, 0, 0, 0.18); border-right: none; border-top: 1px solid rgba(0, 0, 0, 0.18); padding: 0px 0.25rem;&quot;&gt;&lt;code style=&quot;color: var(--vscode-textPreformat-foreground); font-family: var(--vscode-editor-font-family, &amp;quot;SF Mono&amp;quot;, Monaco, Menlo, Consolas, &amp;quot;Ubuntu Mono&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace); font-size: 1em; line-height: 1.357em;&quot;&gt;[0, 2, 4, 6, 8]&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr class=&quot;code-line&quot; data-line=&quot;738&quot; dir=&quot;auto&quot; style=&quot;position: relative;&quot;&gt;&lt;td style=&quot;border-bottom-color: rgba(0, 0, 0, 0.18); border-left: none; border-right-color: rgba(0, 0, 0, 0.18); border-top: 1px solid rgba(0, 0, 0, 0.18); padding: 0px 0.25rem;&quot;&gt;&lt;code style=&quot;color: var(--vscode-textPreformat-foreground); font-family: var(--vscode-editor-font-family, &amp;quot;SF Mono&amp;quot;, Monaco, Menlo, Consolas, &amp;quot;Ubuntu Mono&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace); font-size: 1em; line-height: 1.357em;&quot;&gt;np.linspace&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;border-color: rgba(0, 0, 0, 0.18); border-top-style: solid; border-top-width: 1px; padding: 0px 0.25rem;&quot;&gt;선형 간격의 배열 생성&lt;/td&gt;&lt;td style=&quot;border-color: rgba(0, 0, 0, 0.18); border-top-style: solid; border-top-width: 1px; padding: 0px 0.25rem;&quot;&gt;&lt;code style=&quot;color: var(--vscode-textPreformat-foreground); font-family: var(--vscode-editor-font-family, &amp;quot;SF Mono&amp;quot;, Monaco, Menlo, Consolas, &amp;quot;Ubuntu Mono&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace); font-size: 1em; line-height: 1.357em;&quot;&gt;np.linspace(0, 1, 5)&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;border-bottom-color: rgba(0, 0, 0, 0.18); border-left-color: rgba(0, 0, 0, 0.18); border-right: none; border-top: 1px solid rgba(0, 0, 0, 0.18); padding: 0px 0.25rem;&quot;&gt;&lt;code style=&quot;color: var(--vscode-textPreformat-foreground); font-family: var(--vscode-editor-font-family, &amp;quot;SF Mono&amp;quot;, Monaco, Menlo, Consolas, &amp;quot;Ubuntu Mono&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace); font-size: 1em; line-height: 1.357em;&quot;&gt;[0., 0.25, 0.5, 0.75, 1.]&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr class=&quot;code-line&quot; data-line=&quot;739&quot; dir=&quot;auto&quot; style=&quot;position: relative;&quot;&gt;&lt;td style=&quot;border-bottom-color: rgba(0, 0, 0, 0.18); border-left: none; border-right-color: rgba(0, 0, 0, 0.18); border-top: 1px solid rgba(0, 0, 0, 0.18); padding: 0px 0.25rem;&quot;&gt;&lt;code style=&quot;color: var(--vscode-textPreformat-foreground); font-family: var(--vscode-editor-font-family, &amp;quot;SF Mono&amp;quot;, Monaco, Menlo, Consolas, &amp;quot;Ubuntu Mono&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace); font-size: 1em; line-height: 1.357em;&quot;&gt;np.logspace&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;border-color: rgba(0, 0, 0, 0.18); border-top-style: solid; border-top-width: 1px; padding: 0px 0.25rem;&quot;&gt;로그 간격의 배열 생성&lt;/td&gt;&lt;td style=&quot;border-color: rgba(0, 0, 0, 0.18); border-top-style: solid; border-top-width: 1px; padding: 0px 0.25rem;&quot;&gt;&lt;code style=&quot;color: var(--vscode-textPreformat-foreground); font-family: var(--vscode-editor-font-family, &amp;quot;SF Mono&amp;quot;, Monaco, Menlo, Consolas, &amp;quot;Ubuntu Mono&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace); font-size: 1em; line-height: 1.357em;&quot;&gt;np.logspace(0, 3, 4)&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;border-bottom-color: rgba(0, 0, 0, 0.18); border-left-color: rgba(0, 0, 0, 0.18); border-right: none; border-top: 1px solid rgba(0, 0, 0, 0.18); padding: 0px 0.25rem;&quot;&gt;&lt;code style=&quot;color: var(--vscode-textPreformat-foreground); font-family: var(--vscode-editor-font-family, &amp;quot;SF Mono&amp;quot;, Monaco, Menlo, Consolas, &amp;quot;Ubuntu Mono&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace); font-size: 1em; line-height: 1.357em;&quot;&gt;[1., 10., 100., 1000.]&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr class=&quot;code-line&quot; data-line=&quot;740&quot; dir=&quot;auto&quot; style=&quot;position: relative;&quot;&gt;&lt;td style=&quot;border-bottom-color: rgba(0, 0, 0, 0.18); border-left: none; border-right-color: rgba(0, 0, 0, 0.18); border-top: 1px solid rgba(0, 0, 0, 0.18); padding: 0px 0.25rem;&quot;&gt;&lt;code style=&quot;color: var(--vscode-textPreformat-foreground); font-family: var(--vscode-editor-font-family, &amp;quot;SF Mono&amp;quot;, Monaco, Menlo, Consolas, &amp;quot;Ubuntu Mono&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace); font-size: 1em; line-height: 1.357em;&quot;&gt;np.eye&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;border-color: rgba(0, 0, 0, 0.18); border-top-style: solid; border-top-width: 1px; padding: 0px 0.25rem;&quot;&gt;단위 행렬 생성&lt;/td&gt;&lt;td style=&quot;border-color: rgba(0, 0, 0, 0.18); border-top-style: solid; border-top-width: 1px; padding: 0px 0.25rem;&quot;&gt;&lt;code style=&quot;color: var(--vscode-textPreformat-foreground); font-family: var(--vscode-editor-font-family, &amp;quot;SF Mono&amp;quot;, Monaco, Menlo, Consolas, &amp;quot;Ubuntu Mono&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace); font-size: 1em; line-height: 1.357em;&quot;&gt;np.eye(3)&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;border-bottom-color: rgba(0, 0, 0, 0.18); border-left-color: rgba(0, 0, 0, 0.18); border-right: none; border-top: 1px solid rgba(0, 0, 0, 0.18); padding: 0px 0.25rem;&quot;&gt;&lt;code style=&quot;color: var(--vscode-textPreformat-foreground); font-family: var(--vscode-editor-font-family, &amp;quot;SF Mono&amp;quot;, Monaco, Menlo, Consolas, &amp;quot;Ubuntu Mono&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace); font-size: 1em; line-height: 1.357em;&quot;&gt;[[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]]&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr class=&quot;code-line&quot; data-line=&quot;741&quot; dir=&quot;auto&quot; style=&quot;position: relative;&quot;&gt;&lt;td style=&quot;border-bottom-color: rgba(0, 0, 0, 0.18); border-left: none; border-right-color: rgba(0, 0, 0, 0.18); border-top: 1px solid rgba(0, 0, 0, 0.18); padding: 0px 0.25rem;&quot;&gt;&lt;code style=&quot;color: var(--vscode-textPreformat-foreground); font-family: var(--vscode-editor-font-family, &amp;quot;SF Mono&amp;quot;, Monaco, Menlo, Consolas, &amp;quot;Ubuntu Mono&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace); font-size: 1em; line-height: 1.357em;&quot;&gt;np.random.rand&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;border-color: rgba(0, 0, 0, 0.18); border-top-style: solid; border-top-width: 1px; padding: 0px 0.25rem;&quot;&gt;랜덤한 원소를 가진 배열 생성&lt;/td&gt;&lt;td style=&quot;border-color: rgba(0, 0, 0, 0.18); border-top-style: solid; border-top-width: 1px; padding: 0px 0.25rem;&quot;&gt;&lt;code style=&quot;color: var(--vscode-textPreformat-foreground); font-family: var(--vscode-editor-font-family, &amp;quot;SF Mono&amp;quot;, Monaco, Menlo, Consolas, &amp;quot;Ubuntu Mono&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace); font-size: 1em; line-height: 1.357em;&quot;&gt;np.random.rand(2, 2)&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;border-bottom-color: rgba(0, 0, 0, 0.18); border-left-color: rgba(0, 0, 0, 0.18); border-right: none; border-top: 1px solid rgba(0, 0, 0, 0.18); padding: 0px 0.25rem;&quot;&gt;랜덤 값 (0~1 사이)&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;h2 class=&quot;code-line&quot; data-line=&quot;743&quot; dir=&quot;auto&quot; id=&quot;%EC%98%88%EC%A0%9C-%EC%BD%94%EB%93%9C&quot; style=&quot;border-bottom: 1px solid rgba(0, 0, 0, 0.18); border-left-color: rgba(0, 0, 0, 0.18); border-right-color: rgba(0, 0, 0, 0.18); border-top-color: rgba(0, 0, 0, 0.18); color: #3b3b3b; font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Segoe WPC&amp;quot;, &amp;quot;Segoe UI&amp;quot;, system-ui, Ubuntu, &amp;quot;Droid Sans&amp;quot;, sans-serif; line-height: 1.25; margin-bottom: 16px; margin-top: 24px; padding-bottom: 0.3em; position: relative;&quot;&gt;예제 코드&lt;/h2&gt;&lt;pre style=&quot;border-radius: 3px; color: #3b3b3b; font-size: 14px; margin-top: 0px; overflow: auto; padding: 16px; text-wrap: wrap;&quot;&gt;&lt;code class=&quot;code-line language-python&quot; data-line=&quot;745&quot; dir=&quot;auto&quot; style=&quot;color: var(--vscode-editor-foreground); font-family: var(--vscode-editor-font-family, &amp;quot;SF Mono&amp;quot;, Monaco, Menlo, Consolas, &amp;quot;Ubuntu Mono&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace); font-size: 1em; line-height: 1.357em; position: relative; tab-size: 4;&quot;&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;color: blue;&quot;&gt;import&lt;/span&gt; numpy &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: blue;&quot;&gt;as&lt;/span&gt; np

&lt;span class=&quot;hljs-comment&quot; style=&quot;color: green; font-style: italic;&quot;&gt;# np.array 예제&lt;/span&gt;
a = np.array([&lt;span class=&quot;hljs-number&quot; style=&quot;color: green;&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot; style=&quot;color: green;&quot;&gt;2&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot; style=&quot;color: green;&quot;&gt;3&lt;/span&gt;])
&lt;span class=&quot;hljs-built_in&quot; style=&quot;color: #007acc;&quot;&gt;print&lt;/span&gt;(&lt;span class=&quot;hljs-string&quot; style=&quot;color: #a31515;&quot;&gt;&quot;np.array:&quot;&lt;/span&gt;, a)

&lt;span class=&quot;hljs-comment&quot; style=&quot;color: green; font-style: italic;&quot;&gt;# np.zeros 예제&lt;/span&gt;
b = np.zeros((&lt;span class=&quot;hljs-number&quot; style=&quot;color: green;&quot;&gt;2&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot; style=&quot;color: green;&quot;&gt;3&lt;/span&gt;))
&lt;span class=&quot;hljs-built_in&quot; style=&quot;color: #007acc;&quot;&gt;print&lt;/span&gt;(&lt;span class=&quot;hljs-string&quot; style=&quot;color: #a31515;&quot;&gt;&quot;np.zeros:&quot;&lt;/span&gt;, b)

&lt;span class=&quot;hljs-comment&quot; style=&quot;color: green; font-style: italic;&quot;&gt;# np.ones 예제&lt;/span&gt;
c = np.ones((&lt;span class=&quot;hljs-number&quot; style=&quot;color: green;&quot;&gt;3&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot; style=&quot;color: green;&quot;&gt;2&lt;/span&gt;))
&lt;span class=&quot;hljs-built_in&quot; style=&quot;color: #007acc;&quot;&gt;print&lt;/span&gt;(&lt;span class=&quot;hljs-string&quot; style=&quot;color: #a31515;&quot;&gt;&quot;np.ones:&quot;&lt;/span&gt;, c)

&lt;span class=&quot;hljs-comment&quot; style=&quot;color: green; font-style: italic;&quot;&gt;# np.empty 예제&lt;/span&gt;
d = np.empty((&lt;span class=&quot;hljs-number&quot; style=&quot;color: green;&quot;&gt;2&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot; style=&quot;color: green;&quot;&gt;2&lt;/span&gt;))
&lt;span class=&quot;hljs-built_in&quot; style=&quot;color: #007acc;&quot;&gt;print&lt;/span&gt;(&lt;span class=&quot;hljs-string&quot; style=&quot;color: #a31515;&quot;&gt;&quot;np.empty:&quot;&lt;/span&gt;, d)

&lt;span class=&quot;hljs-comment&quot; style=&quot;color: green; font-style: italic;&quot;&gt;# np.arange 예제&lt;/span&gt;
e = np.arange(&lt;span class=&quot;hljs-number&quot; style=&quot;color: green;&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot; style=&quot;color: green;&quot;&gt;10&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot; style=&quot;color: green;&quot;&gt;2&lt;/span&gt;)
&lt;span class=&quot;hljs-built_in&quot; style=&quot;color: #007acc;&quot;&gt;print&lt;/span&gt;(&lt;span class=&quot;hljs-string&quot; style=&quot;color: #a31515;&quot;&gt;&quot;np.arange:&quot;&lt;/span&gt;, e)

&lt;span class=&quot;hljs-comment&quot; style=&quot;color: green; font-style: italic;&quot;&gt;# np.linspace 예제&lt;/span&gt;
f = np.linspace(&lt;span class=&quot;hljs-number&quot; style=&quot;color: green;&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot; style=&quot;color: green;&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot; style=&quot;color: green;&quot;&gt;5&lt;/span&gt;)
&lt;span class=&quot;hljs-built_in&quot; style=&quot;color: #007acc;&quot;&gt;print&lt;/span&gt;(&lt;span class=&quot;hljs-string&quot; style=&quot;color: #a31515;&quot;&gt;&quot;np.linspace:&quot;&lt;/span&gt;, f)

&lt;span class=&quot;hljs-comment&quot; style=&quot;color: green; font-style: italic;&quot;&gt;# np.logspace 예제&lt;/span&gt;
g = np.logspace(&lt;span class=&quot;hljs-number&quot; style=&quot;color: green;&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot; style=&quot;color: green;&quot;&gt;3&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot; style=&quot;color: green;&quot;&gt;4&lt;/span&gt;)
&lt;span class=&quot;hljs-built_in&quot; style=&quot;color: #007acc;&quot;&gt;print&lt;/span&gt;(&lt;span class=&quot;hljs-string&quot; style=&quot;color: #a31515;&quot;&gt;&quot;np.logspace:&quot;&lt;/span&gt;, g)

&lt;span class=&quot;hljs-comment&quot; style=&quot;color: green; font-style: italic;&quot;&gt;# np.eye 예제&lt;/span&gt;
h = np.eye(&lt;span class=&quot;hljs-number&quot; style=&quot;color: green;&quot;&gt;3&lt;/span&gt;)
&lt;span class=&quot;hljs-built_in&quot; style=&quot;color: #007acc;&quot;&gt;print&lt;/span&gt;(&lt;span class=&quot;hljs-string&quot; style=&quot;color: #a31515;&quot;&gt;&quot;np.eye:&quot;&lt;/span&gt;, h)

&lt;span class=&quot;hljs-comment&quot; style=&quot;color: green; font-style: italic;&quot;&gt;# np.random.rand 예제&lt;/span&gt;
i = np.random.rand(&lt;span class=&quot;hljs-number&quot; style=&quot;color: green;&quot;&gt;2&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot; style=&quot;color: green;&quot;&gt;2&lt;/span&gt;)
&lt;span class=&quot;hljs-built_in&quot; style=&quot;color: #007acc;&quot;&gt;print&lt;/span&gt;(&lt;span class=&quot;hljs-string&quot; style=&quot;color: #a31515;&quot;&gt;&quot;np.random.rand:&quot;&lt;/span&gt;, i)
&lt;/code&gt;&lt;/pre&gt;&lt;p class=&quot;code-line&quot; data-line=&quot;785&quot; dir=&quot;auto&quot; style=&quot;color: #3b3b3b; font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Segoe WPC&amp;quot;, &amp;quot;Segoe UI&amp;quot;, system-ui, Ubuntu, &amp;quot;Droid Sans&amp;quot;, sans-serif; font-size: 14px; margin-bottom: 16px; margin-top: 0px; position: relative;&quot;&gt;이러한 NumPy 함수들을 사용하여 다양한 형태와 속성을 가진 배열을 쉽게 생성할 수 있습니다. 각 함수가 어떤 상황에 유용한지를 이해하면, 이부분 사용하는데 문제없을 듯 합니다.&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://pyengine.blogspot.com/feeds/6167057356440908960/comments/default' title='댓글'/><link rel='replies' type='text/html' href='http://pyengine.blogspot.com/2023/09/numpy-array.html#comment-form' title='0개의 덧글'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4881868893095669586/posts/default/6167057356440908960'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4881868893095669586/posts/default/6167057356440908960'/><link rel='alternate' type='text/html' href='http://pyengine.blogspot.com/2023/09/numpy-array.html' title='NumPy Array 생성 함수'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4881868893095669586.post-8723479983190504841</id><published>2023-09-06T00:30:00.006+09:00</published><updated>2023-09-06T00:30:00.145+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="broadcasting"/><category scheme="http://www.blogger.com/atom/ns#" term="numpy"/><category scheme="http://www.blogger.com/atom/ns#" term="파이썬"/><title type='text'>NumPy Broadcasting</title><content type='html'>&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p class=&quot;code-line&quot; data-line=&quot;609&quot; dir=&quot;auto&quot; style=&quot;font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Segoe WPC&amp;quot;, &amp;quot;Segoe UI&amp;quot;, system-ui, Ubuntu, &amp;quot;Droid Sans&amp;quot;, sans-serif; font-size: 14px; margin-bottom: 16px; margin-top: 0px; position: relative;&quot;&gt;Broadcasting은 NumPy 라이브러리에서 다른 형태(shape)의 배열 간에도 산술 연산이 가능하게 해주는 기능입니다. 일반적으로, NumPy에서 배열 간 연산은 배열의 형태가 동일해야 하는데, Broadcasting은 이러한 제약을 완화해줍니다.&lt;/p&gt;&lt;h2 class=&quot;code-line&quot; data-line=&quot;611&quot; dir=&quot;auto&quot; id=&quot;%EA%B8%B0%EB%B3%B8-%EA%B7%9C%EC%B9%99&quot; style=&quot;border-bottom: 1px solid rgba(0, 0, 0, 0.18); border-left-color: rgba(0, 0, 0, 0.18); border-right-color: rgba(0, 0, 0, 0.18); border-top-color: rgba(0, 0, 0, 0.18); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Segoe WPC&amp;quot;, &amp;quot;Segoe UI&amp;quot;, system-ui, Ubuntu, &amp;quot;Droid Sans&amp;quot;, sans-serif; line-height: 1.25; margin-bottom: 16px; margin-top: 24px; padding-bottom: 0.3em; position: relative;&quot;&gt;기본 규칙&lt;/h2&gt;&lt;p class=&quot;code-line&quot; data-line=&quot;613&quot; dir=&quot;auto&quot; style=&quot;font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Segoe WPC&amp;quot;, &amp;quot;Segoe UI&amp;quot;, system-ui, Ubuntu, &amp;quot;Droid Sans&amp;quot;, sans-serif; font-size: 14px; margin-bottom: 16px; margin-top: 0px; position: relative;&quot;&gt;Broadcasting은 다음과 같은 규칙을 따릅니다:&lt;/p&gt;&lt;ol class=&quot;code-line&quot; data-line=&quot;615&quot; dir=&quot;auto&quot; style=&quot;font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Segoe WPC&amp;quot;, &amp;quot;Segoe UI&amp;quot;, system-ui, Ubuntu, &amp;quot;Droid Sans&amp;quot;, sans-serif; font-size: 14px; margin-bottom: 0.7em; margin-top: 0px; position: relative;&quot;&gt;&lt;li class=&quot;code-line&quot; data-line=&quot;615&quot; dir=&quot;auto&quot; style=&quot;position: relative;&quot;&gt;두 배열의 차원 수가 다르면, 더 작은 차원을 가진 배열의 형태(shape) 앞에 1을 추가합니다.&lt;/li&gt;&lt;li class=&quot;code-line&quot; data-line=&quot;616&quot; dir=&quot;auto&quot; style=&quot;position: relative;&quot;&gt;두 배열이 어떤 차원에서도 크기가 동일하거나, 한쪽이 1이라면 호환되는 것으로 간주됩니다.&lt;/li&gt;&lt;li class=&quot;code-line&quot; data-line=&quot;617&quot; dir=&quot;auto&quot; style=&quot;position: relative;&quot;&gt;어느 한 차원에서도 크기가 일치하지 않고 1도 아니라면 오류가 발생합니다.&lt;/li&gt;&lt;/ol&gt;&lt;p class=&quot;code-line&quot; data-line=&quot;619&quot; dir=&quot;auto&quot; style=&quot;font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Segoe WPC&amp;quot;, &amp;quot;Segoe UI&amp;quot;, system-ui, Ubuntu, &amp;quot;Droid Sans&amp;quot;, sans-serif; font-size: 14px; margin-bottom: 16px; margin-top: 0px; position: relative;&quot;&gt;이것 말은 어려운데 실제 동작하는것보면 쉽게 이해할 수 있습니다.&lt;/p&gt;&lt;h2 class=&quot;code-line&quot; data-line=&quot;621&quot; dir=&quot;auto&quot; id=&quot;%EC%98%88%EC%A0%9C&quot; style=&quot;border-bottom: 1px solid rgba(0, 0, 0, 0.18); border-left-color: rgba(0, 0, 0, 0.18); border-right-color: rgba(0, 0, 0, 0.18); border-top-color: rgba(0, 0, 0, 0.18); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Segoe WPC&amp;quot;, &amp;quot;Segoe UI&amp;quot;, system-ui, Ubuntu, &amp;quot;Droid Sans&amp;quot;, sans-serif; line-height: 1.25; margin-bottom: 16px; margin-top: 24px; padding-bottom: 0.3em; position: relative;&quot;&gt;예제&lt;/h2&gt;&lt;h3 class=&quot;code-line&quot; data-line=&quot;621&quot; dir=&quot;auto&quot; id=&quot;%EC%98%88%EC%A0%9C-1-%EB%B2%A1%ED%84%B0%EC%99%80-%EC%8A%A4%EC%B9%BC%EB%9D%BC-%EB%8D%A7%EC%85%88&quot; style=&quot;font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Segoe WPC&amp;quot;, &amp;quot;Segoe UI&amp;quot;, system-ui, Ubuntu, &amp;quot;Droid Sans&amp;quot;, sans-serif; font-size: 1.25em; line-height: 1.25; margin-bottom: 16px; margin-top: 24px; position: relative;&quot;&gt;예제 1: 벡터와 스칼라 덧셈&lt;/h3&gt;&lt;pre style=&quot;border-radius: 3px; font-size: 14px; margin-top: 0px; overflow: auto; padding: 16px; text-wrap: wrap;&quot;&gt;&lt;code class=&quot;code-line language-python&quot; data-line=&quot;625&quot; dir=&quot;auto&quot; style=&quot;color: var(--vscode-editor-foreground); font-family: var(--vscode-editor-font-family, &amp;quot;SF Mono&amp;quot;, Monaco, Menlo, Consolas, &amp;quot;Ubuntu Mono&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace); font-size: 1em; line-height: 1.357em; position: relative; tab-size: 4;&quot;&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;color: blue;&quot;&gt;import&lt;/span&gt; numpy &lt;span class=&quot;hljs-keyword&quot; style=&quot;color: blue;&quot;&gt;as&lt;/span&gt; np

a = np.array([&lt;span class=&quot;hljs-number&quot; style=&quot;color: green;&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot; style=&quot;color: green;&quot;&gt;2&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot; style=&quot;color: green;&quot;&gt;3&lt;/span&gt;])
b = &lt;span class=&quot;hljs-number&quot; style=&quot;color: green;&quot;&gt;2&lt;/span&gt;

result = a + b
&lt;span class=&quot;hljs-comment&quot; style=&quot;color: green; font-style: italic;&quot;&gt;# result: array([3, 4, 5])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;h3 class=&quot;code-line&quot; data-line=&quot;633&quot; dir=&quot;auto&quot; id=&quot;%EC%98%88%EC%A0%9C-2-2%EC%B0%A8%EC%9B%90-%EB%B0%B0%EC%97%B4%EA%B3%BC-1%EC%B0%A8%EC%9B%90-%EB%B0%B0%EC%97%B4-%EB%8D%A7%EC%85%88&quot; style=&quot;font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Segoe WPC&amp;quot;, &amp;quot;Segoe UI&amp;quot;, system-ui, Ubuntu, &amp;quot;Droid Sans&amp;quot;, sans-serif; font-size: 1.25em; line-height: 1.25; margin-bottom: 16px; margin-top: 24px; position: relative;&quot;&gt;예제 2: 2차원 배열과 1차원 배열 덧셈&lt;/h3&gt;&lt;pre style=&quot;border-radius: 3px; font-size: 14px; margin-top: 0px; overflow: auto; padding: 16px; text-wrap: wrap;&quot;&gt;&lt;code class=&quot;code-line language-python&quot; data-line=&quot;637&quot; dir=&quot;auto&quot; style=&quot;color: var(--vscode-editor-foreground); font-family: var(--vscode-editor-font-family, &amp;quot;SF Mono&amp;quot;, Monaco, Menlo, Consolas, &amp;quot;Ubuntu Mono&amp;quot;, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, monospace); font-size: 1em; line-height: 1.357em; position: relative; tab-size: 4;&quot;&gt;A = np.array([[&lt;span class=&quot;hljs-number&quot; style=&quot;color: green;&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot; style=&quot;color: green;&quot;&gt;2&lt;/span&gt;], [&lt;span class=&quot;hljs-number&quot; style=&quot;color: green;&quot;&gt;3&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot; style=&quot;color: green;&quot;&gt;4&lt;/span&gt;], [&lt;span class=&quot;hljs-number&quot; style=&quot;color: green;&quot;&gt;5&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot; style=&quot;color: green;&quot;&gt;6&lt;/span&gt;]])
B = np.array([&lt;span class=&quot;hljs-number&quot; style=&quot;color: green;&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot; style=&quot;color: green;&quot;&gt;2&lt;/span&gt;])

result = A + B
&lt;span class=&quot;hljs-comment&quot; style=&quot;color: green; font-style: italic;&quot;&gt;# result: array([[2, 4], [4, 6], [6, 8]])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;h2 class=&quot;code-line&quot; data-line=&quot;643&quot; dir=&quot;auto&quot; id=&quot;%EC%9E%A5%EC%A0%90%EA%B3%BC-%EB%8B%A8%EC%A0%90&quot; style=&quot;border-bottom: 1px solid rgba(0, 0, 0, 0.18); border-left-color: rgba(0, 0, 0, 0.18); border-right-color: rgba(0, 0, 0, 0.18); border-top-color: rgba(0, 0, 0, 0.18); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Segoe WPC&amp;quot;, &amp;quot;Segoe UI&amp;quot;, system-ui, Ubuntu, &amp;quot;Droid Sans&amp;quot;, sans-serif; line-height: 1.25; margin-bottom: 16px; margin-top: 24px; padding-bottom: 0.3em; position: relative;&quot;&gt;장점과 단점&lt;/h2&gt;&lt;h3 class=&quot;code-line&quot; data-line=&quot;645&quot; dir=&quot;auto&quot; id=&quot;%EC%9E%A5%EC%A0%90&quot; style=&quot;font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Segoe WPC&amp;quot;, &amp;quot;Segoe UI&amp;quot;, system-ui, Ubuntu, &amp;quot;Droid Sans&amp;quot;, sans-serif; font-size: 1.25em; line-height: 1.25; margin-bottom: 16px; margin-top: 24px; position: relative;&quot;&gt;장점&lt;/h3&gt;&lt;ul class=&quot;code-line&quot; data-line=&quot;649&quot; dir=&quot;auto&quot; style=&quot;font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Segoe WPC&amp;quot;, &amp;quot;Segoe UI&amp;quot;, system-ui, Ubuntu, &amp;quot;Droid Sans&amp;quot;, sans-serif; font-size: 14px; margin-bottom: 0.7em; margin-top: 0px; position: relative;&quot;&gt;&lt;li class=&quot;code-line&quot; data-line=&quot;649&quot; dir=&quot;auto&quot; style=&quot;position: relative;&quot;&gt;&lt;strong&gt;간결성&lt;/strong&gt;: 더 적은 메모리와 코드로 같은 연산을 수행할 수 있습니다.&lt;/li&gt;&lt;li class=&quot;code-line&quot; data-line=&quot;650&quot; dir=&quot;auto&quot; style=&quot;position: relative;&quot;&gt;&lt;strong&gt;성능&lt;/strong&gt;: Broadcasting을 이용한 연산은 내부적으로 최적화되어 있어 빠른 연산 속도를 제공합니다.&lt;/li&gt;&lt;/ul&gt;&lt;h3 class=&quot;code-line&quot; data-line=&quot;650&quot; dir=&quot;auto&quot; id=&quot;%EB%8B%A8%EC%A0%90&quot; style=&quot;font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Segoe WPC&amp;quot;, &amp;quot;Segoe UI&amp;quot;, system-ui, Ubuntu, &amp;quot;Droid Sans&amp;quot;, sans-serif; font-size: 1.25em; line-height: 1.25; margin-bottom: 16px; margin-top: 24px; position: relative;&quot;&gt;단점&lt;/h3&gt;&lt;ul class=&quot;code-line&quot; data-line=&quot;654&quot; dir=&quot;auto&quot; style=&quot;font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Segoe WPC&amp;quot;, &amp;quot;Segoe UI&amp;quot;, system-ui, Ubuntu, &amp;quot;Droid Sans&amp;quot;, sans-serif; font-size: 14px; margin-bottom: 0.7em; margin-top: 0px; position: relative;&quot;&gt;&lt;li class=&quot;code-line&quot; data-line=&quot;654&quot; dir=&quot;auto&quot; style=&quot;position: relative;&quot;&gt;&lt;strong&gt;복잡성&lt;/strong&gt;: Broadcasting 규칙을 이해하지 못하면 예상치 못한 결과를 얻을 수 있습니다.&lt;/li&gt;&lt;li class=&quot;code-line&quot; data-line=&quot;655&quot; dir=&quot;auto&quot; style=&quot;position: relative;&quot;&gt;&lt;strong&gt;디버깅&lt;/strong&gt;: 문제가 발생했을 때, 디버깅이 상대적으로 어렵습니다.&lt;/li&gt;&lt;/ul&gt;&lt;h2 class=&quot;code-line&quot; data-line=&quot;655&quot; dir=&quot;auto&quot; id=&quot;%EA%B2%B0%EB%A1%A0&quot; style=&quot;border-bottom: 1px solid rgba(0, 0, 0, 0.18); border-left-color: rgba(0, 0, 0, 0.18); border-right-color: rgba(0, 0, 0, 0.18); border-top-color: rgba(0, 0, 0, 0.18); font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Segoe WPC&amp;quot;, &amp;quot;Segoe UI&amp;quot;, system-ui, Ubuntu, &amp;quot;Droid Sans&amp;quot;, sans-serif; line-height: 1.25; margin-bottom: 16px; margin-top: 24px; padding-bottom: 0.3em; position: relative;&quot;&gt;결론&lt;/h2&gt;&lt;p class=&quot;code-line&quot; data-line=&quot;659&quot; dir=&quot;auto&quot; style=&quot;font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Segoe WPC&amp;quot;, &amp;quot;Segoe UI&amp;quot;, system-ui, Ubuntu, &amp;quot;Droid Sans&amp;quot;, sans-serif; font-size: 14px; margin-bottom: 16px; margin-top: 0px; position: relative;&quot;&gt;NumPy의 Broadcasting 기능은 배열 연산을 더 간편하고 빠르게 해주지만, 사용에 앞서 해당 메커니즘을 잘 이해하는 것이 중요합니다. 잘 활용하면 다양한 수학적 문제와 데이터 분석 작업에서 큰 이점을 볼 수 있습니다.&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://pyengine.blogspot.com/feeds/8723479983190504841/comments/default' title='댓글'/><link rel='replies' type='text/html' href='http://pyengine.blogspot.com/2023/09/numpy-broadcasting.html#comment-form' title='0개의 덧글'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4881868893095669586/posts/default/8723479983190504841'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4881868893095669586/posts/default/8723479983190504841'/><link rel='alternate' type='text/html' href='http://pyengine.blogspot.com/2023/09/numpy-broadcasting.html' title='NumPy Broadcasting'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4881868893095669586.post-8753363478156606225</id><published>2023-07-23T20:31:00.006+09:00</published><updated>2023-07-23T20:31:39.808+09:00</updated><title type='text'>리눅스에서 pdf 파일 합치는 방법</title><content type='html'>우분투에서 다음 방법으로&lt;br /&gt;
pdftk 를 설치한다&lt;br /&gt;
&lt;br /&gt;
sudo apt-get install pdftk&lt;br /&gt;
&lt;br /&gt;&lt;div&gt;&lt;div&gt;Linux에서 PDF 파일을 합치려면, pdftk라는 명령어 도구를 활용하면 된다. pdftk는 PDF 문서를 합치는 작업부터 페이지 회전, 삭제, 메타데이터 수정 등 다양한 기능을 제공한다.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;만약 pdftk가 설치되어 있지 않다면, 아래의 명령어로 설치하면 된다.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Ubuntu 혹은 Debian 기반의 시스템인 경우:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div style=&quot;background-color: #1e1e1e; color: #dadada; font-family: Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 14px; line-height: 19px; white-space: pre;&quot;&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: #dcdcaa;&quot;&gt;&amp;gt; sudo&lt;/span&gt; &lt;span style=&quot;color: #ce9178;&quot;&gt;apt-get&lt;/span&gt; &lt;span style=&quot;color: #ce9178;&quot;&gt;install&lt;/span&gt; &lt;span style=&quot;color: #ce9178;&quot;&gt;pdftk&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;설치가 완료되면, pdftk 명령어를 활용해 PDF 파일을 합칠 수 있다. 예를 들어, file1.pdf와 file2.pdf 두 파일을 output.pdf라는 하나의 파일로 합치려면 아래와 같이 실행하면 된다.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div style=&quot;background-color: #1e1e1e; color: #dadada; font-family: Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 14px; line-height: 19px; white-space: pre;&quot;&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: #dcdcaa;&quot;&gt;&amp;gt; pdftk&lt;/span&gt; &lt;span style=&quot;color: #ce9178;&quot;&gt;file1.pdf&lt;/span&gt; &lt;span style=&quot;color: #ce9178;&quot;&gt;file2.pdf&lt;/span&gt; &lt;span style=&quot;color: #ce9178;&quot;&gt;cat&lt;/span&gt; &lt;span style=&quot;color: #ce9178;&quot;&gt;output&lt;/span&gt; &lt;span style=&quot;color: #ce9178;&quot;&gt;output.pdf&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;여기서 cat 옵션은 입력된 파일들을 순서대로 연결해 하나의 출력 파일을 생성한다는 것을 의미한다. output 키워드 다음에는 생성될 파일의 이름을 지정하면 된다.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;또한 pdftk는 페이지 순서 변경이나 특정 페이지만 추출하는 등의 다양한 고급 기능도 제공한다. 자세한 내용은 man pdftk 명령어를 통해 pdftk의 매뉴얼 페이지를 확인하면 된다.&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://pyengine.blogspot.com/feeds/8753363478156606225/comments/default' title='댓글'/><link rel='replies' type='text/html' href='http://pyengine.blogspot.com/2018/01/pdf.html#comment-form' title='0개의 덧글'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4881868893095669586/posts/default/8753363478156606225'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4881868893095669586/posts/default/8753363478156606225'/><link rel='alternate' type='text/html' href='http://pyengine.blogspot.com/2018/01/pdf.html' title='리눅스에서 pdf 파일 합치는 방법'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4881868893095669586.post-1352943391402261620</id><published>2022-12-11T00:00:00.003+09:00</published><updated>2022-12-11T00:00:00.174+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="3.9"/><category scheme="http://www.blogger.com/atom/ns#" term="gcd"/><category scheme="http://www.blogger.com/atom/ns#" term="lcm"/><category scheme="http://www.blogger.com/atom/ns#" term="math"/><category scheme="http://www.blogger.com/atom/ns#" term="nextafter"/><category scheme="http://www.blogger.com/atom/ns#" term="python"/><category scheme="http://www.blogger.com/atom/ns#" term="ulp"/><title type='text'>파이썬 math (nextafter, ulp, gcd, lcm) (3.9이상)</title><content type='html'>&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;h2 style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: &amp;quot;Roboto Slab&amp;quot;, ff-tisa-web-pro, Georgia, Arial, sans-serif; font-size: 24px; margin-bottom: 24px; margin-top: 0px;&quot;&gt;math update&lt;a class=&quot;headerlink&quot; href=&quot;file://wsl.localhost/Ubuntu-22.04/home/student/works/sphinx/python/build/html/python3_9.html#math-update&quot; style=&quot;-webkit-font-smoothing: antialiased; box-sizing: border-box; color: #2980b9; cursor: pointer; display: inline-block; font-family: FontAwesome; font-size: 14px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; font-weight: normal; line-height: 1; margin-left: 0.5em; opacity: 0; text-decoration-line: none; text-rendering: auto;&quot; title=&quot;이 표제에 대한 퍼머링크&quot;&gt;&lt;/a&gt;&lt;/h2&gt;&lt;p style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;파이썬 3.9 math함수들이 업데이트 되었습니다 이번에는 이 변경점들에 대해서 알아보도록 하겠습니다.&lt;/p&gt;&lt;section id=&quot;nextafter-ulp&quot; style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px;&quot;&gt;&lt;h3 style=&quot;box-sizing: border-box; font-family: &amp;quot;Roboto Slab&amp;quot;, ff-tisa-web-pro, Georgia, Arial, sans-serif; font-size: 20px; margin-bottom: 24px; margin-top: 0px;&quot;&gt;nextafter, ulp&lt;a class=&quot;headerlink&quot; href=&quot;file://wsl.localhost/Ubuntu-22.04/home/student/works/sphinx/python/build/html/python3_9.html#nextafter-ulp&quot; style=&quot;-webkit-font-smoothing: antialiased; box-sizing: border-box; color: #2980b9; cursor: pointer; display: inline-block; font-family: FontAwesome; font-size: 14px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; font-weight: normal; line-height: 1; margin-left: 0.5em; opacity: 0; text-decoration-line: none; text-rendering: auto;&quot; title=&quot;이 표제에 대한 퍼머링크&quot;&gt;&lt;/a&gt;&lt;/h3&gt;&lt;p style=&quot;box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;파이썬 3.9에 추가된 이 함수는 부동소수점에서 나타낼 수 있는 가장 작은 다음 값을 찾아줍니다. (Java에도 동일한 이름의 함수가 존재합니다.)&lt;/p&gt;&lt;p style=&quot;box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;진정한 실수(floating point)에서는 두 수사이에 무한대 개수의 값이 있지만, 실제 컴퓨터는 이것은 floating point를 표현하는 방법이 IEEE-754 기반으로 표현하기때문에, 유한개의 숫자가 존재하고, 이중 가장 근접한 값을 찾아주는 함수입니다. 파이썬 뿐 아니라 대부분의 언어들이 IEEE-754로 floating point를 처리하기 때문에 비슷한 부분이 있습니다.&lt;/p&gt;&lt;p style=&quot;box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;마찬가지로 ulp함수도, 유효숫자기반의 가장 작은 숫자, 즉 오차범위을 알려줍니다. y를 향한 x 다음의 부동 소수점 값을 반환합니다. x가 y와 같으면, y를 반환합니다.&lt;/p&gt;&lt;p style=&quot;box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;다음 예제를 참고 바랍니다 아래와 같이 특정 숫자의 가장 작게 차이는&lt;/p&gt;&lt;div class=&quot;highlight-py notranslate&quot; style=&quot;border: 1px solid rgb(225, 228, 229); box-sizing: border-box; margin: 1px 0px 24px; overflow-x: auto;&quot;&gt;&lt;div class=&quot;highlight&quot; style=&quot;background: rgb(248, 248, 248); border: none; box-sizing: border-box; margin: 0px; overflow-x: auto; padding: 0px;&quot;&gt;&lt;pre style=&quot;box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; line-height: 1.4; margin-bottom: 0px; margin-top: 0px; overflow: auto; padding: 12px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kn&quot; style=&quot;box-sizing: border-box; color: green; font-weight: bold;&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot; style=&quot;box-sizing: border-box; color: blue; font-weight: bold;&quot;&gt;math&lt;/span&gt; &lt;span class=&quot;kn&quot; style=&quot;box-sizing: border-box; color: green; font-weight: bold;&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;nextafter&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;ulp&lt;/span&gt;

&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;nextafter&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;# 2와 3사이의 next floating point value&lt;/span&gt;
&lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;# 2.0000000000000004&lt;/span&gt;

&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;nextafter&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;# 6.000000000000001&lt;/span&gt;

&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;nextafter&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;9&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;#5e-324&lt;/span&gt;
&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;nextafter&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;9&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;#8.999999999999998&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p style=&quot;box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;ulp함수를 찍어보면,&lt;/p&gt;&lt;div class=&quot;highlight-py notranslate&quot; style=&quot;border: 1px solid rgb(225, 228, 229); box-sizing: border-box; margin: 1px 0px 24px; overflow-x: auto;&quot;&gt;&lt;div class=&quot;highlight&quot; style=&quot;background: rgb(248, 248, 248); border: none; box-sizing: border-box; margin: 0px; overflow-x: auto; padding: 0px;&quot;&gt;&lt;pre style=&quot;box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; line-height: 1.4; margin-bottom: 0px; margin-top: 0px; overflow: auto; padding: 12px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;ulp&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;ulp&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mf&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;3.14159265&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;# 4.440892098500626e-16&lt;/span&gt;
&lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;# 4.440892098500626e-16&lt;/span&gt;
&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;ulp&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;100_000_000_000_000_000&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;ulp&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;10_000_000_000_000_000&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;ulp&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;10_000_000_000_000&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;ulp&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;10_000_000_000&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;))&lt;/span&gt;

&lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;# 16.0&lt;/span&gt;
&lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;# 2.0&lt;/span&gt;
&lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;# 0.001953125&lt;/span&gt;
&lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;# 1.9073486328125e-06&lt;/span&gt;

&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p style=&quot;box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;ulp함수를 찍어보면, 큰 수일 수록 한틱이 움직일때 같이 움직이는 ulp숫자가 커지는 것을 확인할 수가 있습니다. 반대로 수가 작으면 작을 수록 유효한 한틱이 작아지기때문에 그 range만큼 같이 움직이는 것을 볼 수가 있습니다.&lt;/p&gt;&lt;p style=&quot;box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;이 함수는 정밀도가 높은 연산을 할 때, 이때의 오차 범위를 계산할 수 있습니다&lt;/p&gt;&lt;/section&gt;&lt;section id=&quot;gcd-lcm&quot; style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px;&quot;&gt;&lt;h3 style=&quot;box-sizing: border-box; font-family: &amp;quot;Roboto Slab&amp;quot;, ff-tisa-web-pro, Georgia, Arial, sans-serif; font-size: 20px; margin-bottom: 24px; margin-top: 0px;&quot;&gt;gcd(최대공약수), lcm(최소공배수)&lt;/h3&gt;&lt;p style=&quot;box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;기존 파이썬 버전의 최대공약수, 최소공배수를 구하는 gcd, lcm 함수는 인자를 2개밖에 받지 못하였는데, 3.9버전 부터는 인자가 여러개 되어도 문제 없이 동작합니다.&lt;/p&gt;&lt;div class=&quot;highlight-py notranslate&quot; style=&quot;border: 1px solid rgb(225, 228, 229); box-sizing: border-box; margin: 1px 0px 24px; overflow-x: auto;&quot;&gt;&lt;div class=&quot;highlight&quot; style=&quot;background: rgb(248, 248, 248); border: none; box-sizing: border-box; margin: 0px; overflow-x: auto; padding: 0px;&quot;&gt;&lt;pre style=&quot;box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; line-height: 1.4; margin-bottom: 0px; margin-top: 0px; overflow: auto; padding: 12px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kn&quot; style=&quot;box-sizing: border-box; color: green; font-weight: bold;&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot; style=&quot;box-sizing: border-box; color: blue; font-weight: bold;&quot;&gt;math&lt;/span&gt; &lt;span class=&quot;kn&quot; style=&quot;box-sizing: border-box; color: green; font-weight: bold;&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;lcm&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;gcd&lt;/span&gt;

&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;gcd&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;12&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;60&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;84&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;# 12&lt;/span&gt;
&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;gcd&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;24&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;18&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;12&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;# 6&lt;/span&gt;
&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;lcm&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;# 60 &lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p style=&quot;box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;위와 같이 math함수 변경점에 대해서 알아 보았습니다.&lt;/p&gt;&lt;/section&gt;</content><link rel='replies' type='application/atom+xml' href='http://pyengine.blogspot.com/feeds/1352943391402261620/comments/default' title='댓글'/><link rel='replies' type='text/html' href='http://pyengine.blogspot.com/2022/12/math-nextafter-ulp-gcd-lcm-39.html#comment-form' title='0개의 덧글'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4881868893095669586/posts/default/1352943391402261620'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4881868893095669586/posts/default/1352943391402261620'/><link rel='alternate' type='text/html' href='http://pyengine.blogspot.com/2022/12/math-nextafter-ulp-gcd-lcm-39.html' title='파이썬 math (nextafter, ulp, gcd, lcm) (3.9이상)'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4881868893095669586.post-4188547222356329901</id><published>2022-12-04T00:00:00.002+09:00</published><updated>2022-12-04T00:00:00.188+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="array join"/><category scheme="http://www.blogger.com/atom/ns#" term="hstack"/><category scheme="http://www.blogger.com/atom/ns#" term="numpy"/><category scheme="http://www.blogger.com/atom/ns#" term="vstack"/><title type='text'>Numpy Array Join (hstack , vstack)</title><content type='html'>&lt;p&gt;&lt;span style=&quot;background-color: #fcfcfc; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px;&quot;&gt;이번에는 Array Join은 Array를 붙이는 방법을 설명합니다. NumPy에서는 스택 개념을 사용하여 이와 관련하여 여러 기능을 제공합니다. vstack과 hstack이 사용됩니다 아럐 예제를 보면 간단합니다. vstack은 위아래로 쌓습니다. hstack의 경우는 좌우로 확장을 해갑니다.&lt;/span&gt;&lt;/p&gt;&lt;section id=&quot;array-join-hstack-vstack&quot; style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px;&quot;&gt;&lt;div class=&quot;highlight-py notranslate&quot; style=&quot;border: 1px solid rgb(225, 228, 229); box-sizing: border-box; margin: 1px 0px 24px; overflow-x: auto;&quot;&gt;&lt;div class=&quot;highlight&quot; style=&quot;background: rgb(248, 248, 248); border: none; box-sizing: border-box; margin: 0px; overflow-x: auto; padding: 0px;&quot;&gt;&lt;pre style=&quot;box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; line-height: 1.4; margin-bottom: 0px; margin-top: 0px; overflow: auto; padding: 12px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kn&quot; style=&quot;box-sizing: border-box; color: green; font-weight: bold;&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot; style=&quot;box-sizing: border-box; color: blue; font-weight: bold;&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot; style=&quot;box-sizing: border-box; color: green; font-weight: bold;&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;nn&quot; style=&quot;box-sizing: border-box; color: blue; font-weight: bold;&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;A&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;ones&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;B&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;zeros&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;vstack&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;B&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;)))&lt;/span&gt;
&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;hstack&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;B&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;)))&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;&#39;&#39;&#39;&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;# vstack&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;[[1. 1. 1.]&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt; [1. 1. 1.]&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt; [1. 1. 1.]&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt; [0. 0. 0.]&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt; [0. 0. 0.]&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt; [0. 0. 0.]]&lt;/span&gt;

&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;# hstack&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;[[1. 1. 1. 0. 0. 0.]&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt; [1. 1. 1. 0. 0. 0.]&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt; [1. 1. 1. 0. 0. 0.]]&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;&#39;&#39;&#39;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p style=&quot;box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;여러 배열 사이에서 쌓기를 수행하는 두 가지 다른 함수는 column_stack() 및 row_stack()입니다. 이러한 기능은 이전의 두 기능과 다르게 작동합니다. 1차원 배열을 column으로 쌓을지 row방향으로 쌓을지를 정합니다.&lt;/p&gt;&lt;div class=&quot;highlight-py notranslate&quot; style=&quot;border: 1px solid rgb(225, 228, 229); box-sizing: border-box; margin: 1px 0px 24px; overflow-x: auto; text-align: left;&quot;&gt;&lt;div class=&quot;highlight&quot; style=&quot;background: rgb(248, 248, 248); border: none; box-sizing: border-box; margin: 0px; overflow-x: auto; padding: 0px;&quot;&gt;&lt;pre style=&quot;box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; line-height: 1.4; margin-bottom: 0px; margin-top: 0px; overflow: auto; padding: 12px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kn&quot; style=&quot;box-sizing: border-box; color: green; font-weight: bold;&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot; style=&quot;box-sizing: border-box; color: blue; font-weight: bold;&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot; style=&quot;box-sizing: border-box; color: green; font-weight: bold;&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;nn&quot; style=&quot;box-sizing: border-box; color: blue; font-weight: bold;&quot;&gt;np&lt;/span&gt;

&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;])&lt;/span&gt;
&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;b&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;])&lt;/span&gt;
&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;c&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;])&lt;/span&gt;
&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;column_stack&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;row_stack&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;&#39;&#39;&#39;&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;# column_stack&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;[[0 3 6]&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt; [1 4 7]&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt; [2 5 8]]&lt;/span&gt;

&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;#row_stack&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;[[0 1 2]&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt; [3 4 5]&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt; [6 7 8]]&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;&#39;&#39;&#39;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/section&gt;&lt;p&gt; 이상으로 Numpy array join에 대해서 알아보았습니다.&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;
</content><link rel='replies' type='application/atom+xml' href='http://pyengine.blogspot.com/feeds/4188547222356329901/comments/default' title='댓글'/><link rel='replies' type='text/html' href='http://pyengine.blogspot.com/2022/12/numpy-array-join-hstack-vstack.html#comment-form' title='0개의 덧글'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4881868893095669586/posts/default/4188547222356329901'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4881868893095669586/posts/default/4188547222356329901'/><link rel='alternate' type='text/html' href='http://pyengine.blogspot.com/2022/12/numpy-array-join-hstack-vstack.html' title='Numpy Array Join (hstack , vstack)'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4881868893095669586.post-4358590107675143900</id><published>2022-11-28T00:00:00.010+09:00</published><updated>2022-11-28T00:00:00.171+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="|"/><category scheme="http://www.blogger.com/atom/ns#" term="딕셔너리"/><category scheme="http://www.blogger.com/atom/ns#" term="유니온"/><category scheme="http://www.blogger.com/atom/ns#" term="파이썬"/><title type='text'>파이썬 딕셔너리 merge (|) 연산자 추가 (3.9이상)</title><content type='html'>&lt;h1 style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: Nanum Myeongjo;&quot;&gt;유니온 연산자(|)&amp;nbsp;&lt;/span&gt;&lt;/h1&gt;&lt;span style=&quot;font-family: Nanum Myeongjo;&quot;&gt;&lt;div&gt;&lt;span style=&quot;font-family: Nanum Myeongjo;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
딕셔너리에 | (유니온 연산자)를 사용할 수 있습니다. 
값을 병합합니다. 기존의 값이 있으면 새 값으로 업데이트 합니다 
x.update(y) 의 간단한 버전입니다. 

&lt;/span&gt;&lt;pre class=&quot;prettyprint lang-python&quot;&gt;
x = {&quot;k1&quot;: &quot;v1x&quot;, &quot;k2&quot;: &quot;v2x&quot;}
y = {&quot;k2&quot;: &quot;v2y&quot;, &quot;k3&quot;: &quot;v3y&quot;}
print (x | y)
# {&#39;k1&#39;: &#39;v1x&#39;, &#39;k2&#39;: &#39;v2y&#39;, &#39;k3&#39;: &#39;v3y&#39;}
print (y | x)
# {&#39;k1&#39;: &#39;v1x&#39;, &#39;k2&#39;: &#39;v2x&#39;, &#39;k3&#39;: &#39;v3y&#39;}
&lt;/pre&gt;

&lt;span style=&quot;font-family: Nanum Myeongjo;&quot;&gt;
여기서 주의 깊게 볼 건 k2값이 순서에 따라 다른 부분 입니다. 
뒤에 있는 값이 Update되는 값이라 최신이 됩니다. &lt;/span&gt;&lt;div&gt;&lt;span style=&quot;font-family: Nanum Myeongjo;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: Nanum Myeongjo;&quot;&gt;이 기능은 파이썬 3.9에서부터 지원합니다.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;font-family: Nanum Myeongjo;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://pyengine.blogspot.com/feeds/4358590107675143900/comments/default' title='댓글'/><link rel='replies' type='text/html' href='http://pyengine.blogspot.com/2022/11/merge-39.html#comment-form' title='0개의 덧글'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4881868893095669586/posts/default/4358590107675143900'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4881868893095669586/posts/default/4358590107675143900'/><link rel='alternate' type='text/html' href='http://pyengine.blogspot.com/2022/11/merge-39.html' title='파이썬 딕셔너리 merge (|) 연산자 추가 (3.9이상)'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4881868893095669586.post-5969504011144756951</id><published>2022-11-23T23:20:00.004+09:00</published><updated>2023-09-23T08:06:27.110+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="오프라인 설치"/><category scheme="http://www.blogger.com/atom/ns#" term="파이썬 venv"/><title type='text'>Python venv(virtual Environment) 오프라인 설치</title><content type='html'>&lt;br /&gt;&lt;h1 style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: &amp;quot;Roboto Slab&amp;quot;, ff-tisa-web-pro, Georgia, Arial, sans-serif; font-size: 28px; margin-bottom: 24px; margin-top: 0px;&quot;&gt;Venv&lt;/h1&gt;&lt;p style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;virtual 환경은 보통 파이썬 패키지등을 설치하다 보면, 가끔가다가 환경이 꼬이는 경우들이 가끔가다 발생합니다.&lt;/p&gt;&lt;p style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;특히 pip같은 걸로 관리하는 경우는 그래도 좀 수월하지만, 이것 저것 패키지 dependency가 꼬이는 경우들이 종종 있습니다. 이런 것들을 방지 하기 위해서, venv를 사용합니다,&lt;/p&gt;&lt;p style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;이전 python2에는 virtualenv라든지 third-party 지원을 사용했다면, 현재는 python 3.3 부터 venv가 기본 패키지 안으로 들어옴에 따라 그냥 venv를 사용하면 됩니다.&lt;/p&gt;&lt;section id=&quot;id1&quot; style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px;&quot;&gt;&lt;h2 style=&quot;box-sizing: border-box; font-family: &amp;quot;Roboto Slab&amp;quot;, ff-tisa-web-pro, Georgia, Arial, sans-serif; font-size: 24px; margin-bottom: 24px; margin-top: 0px;&quot;&gt;venv 실행&lt;/h2&gt;&lt;p style=&quot;box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;실행법은 아래와 같이 실행하면 됩니다.&lt;/p&gt;&lt;div class=&quot;highlight-bash notranslate&quot; style=&quot;border: 1px solid rgb(225, 228, 229); box-sizing: border-box; margin: 1px 0px 24px; overflow-x: auto;&quot;&gt;&lt;div class=&quot;highlight&quot; style=&quot;background: rgb(248, 248, 248); border: none; box-sizing: border-box; margin: 0px; overflow-x: auto; padding: 0px;&quot;&gt;&lt;pre style=&quot;box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; line-height: 1.4; margin-bottom: 0px; margin-top: 0px; overflow: auto; padding: 12px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;&quot;&gt;&lt;/span&gt;&amp;gt;&amp;gt; python -m venv &lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;[&lt;/span&gt;virtualenv_name&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;]&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p style=&quot;box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;으로 실행하면 됩니다.&lt;/p&gt;&lt;p style=&quot;box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;여기서는 env1 로 만들어 보겠습니다. 리눅스 기준으로는 아래와 같이 실행합니다.&lt;/p&gt;&lt;div class=&quot;highlight-bash notranslate&quot; style=&quot;border: 1px solid rgb(225, 228, 229); box-sizing: border-box; margin: 1px 0px 24px; overflow-x: auto;&quot;&gt;&lt;div class=&quot;highlight&quot; style=&quot;background: rgb(248, 248, 248); border: none; box-sizing: border-box; margin: 0px; overflow-x: auto; padding: 0px;&quot;&gt;&lt;pre style=&quot;box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; line-height: 1.4; margin-bottom: 0px; margin-top: 0px; overflow: auto; padding: 12px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;&quot;&gt;&lt;/span&gt;&amp;gt;&amp;gt; python -m venv env1
&amp;gt;&amp;gt; &lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;cd&lt;/span&gt; env 
&amp;gt;&amp;gt; &lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;source&lt;/span&gt; ./bin/activate
&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;(&lt;/span&gt;env1&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;)&lt;/span&gt; &amp;gt;&amp;gt; 
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p style=&quot;box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;위와 같이 가상환경이 준비된 것을 확인할 수 있습니다. 빠져나올때는&amp;nbsp;&lt;code class=&quot;docutils literal notranslate&quot; style=&quot;background: rgb(255, 255, 255); border: 1px solid rgb(225, 228, 229); box-sizing: border-box; color: #e74c3c; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; max-width: 100%; overflow-x: auto; padding: 2px 5px;&quot;&gt;&lt;span class=&quot;pre&quot; style=&quot;box-sizing: border-box;&quot;&gt;deactive&lt;/span&gt;&lt;/code&gt;&amp;nbsp;를 실행시키면 빠져나올 수 있습니다.&lt;/p&gt;&lt;/section&gt;&lt;section id=&quot;id2&quot; style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px;&quot;&gt;&lt;h2 style=&quot;box-sizing: border-box; font-family: &amp;quot;Roboto Slab&amp;quot;, ff-tisa-web-pro, Georgia, Arial, sans-serif; font-size: 24px; margin-bottom: 24px; margin-top: 0px;&quot;&gt;패키지 확인&lt;/h2&gt;&lt;p style=&quot;box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;다음과 같이&amp;nbsp;&lt;code class=&quot;docutils literal notranslate&quot; style=&quot;background: rgb(255, 255, 255); border: 1px solid rgb(225, 228, 229); box-sizing: border-box; color: #e74c3c; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; max-width: 100%; overflow-x: auto; padding: 2px 5px;&quot;&gt;&lt;span class=&quot;pre&quot; style=&quot;box-sizing: border-box;&quot;&gt;pip&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot; style=&quot;box-sizing: border-box;&quot;&gt;list&lt;/span&gt;&lt;/code&gt;&amp;nbsp;또는&amp;nbsp;&lt;code class=&quot;docutils literal notranslate&quot; style=&quot;background: rgb(255, 255, 255); border: 1px solid rgb(225, 228, 229); box-sizing: border-box; color: #e74c3c; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; max-width: 100%; overflow-x: auto; padding: 2px 5px;&quot;&gt;&lt;span class=&quot;pre&quot; style=&quot;box-sizing: border-box;&quot;&gt;pip&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot; style=&quot;box-sizing: border-box;&quot;&gt;freeze&lt;/span&gt;&lt;/code&gt;&amp;nbsp;를 치면 현재 깔린 패키지들을 확인할 수 있습니다&amp;nbsp;&lt;code class=&quot;docutils literal notranslate&quot; style=&quot;background: rgb(255, 255, 255); border: 1px solid rgb(225, 228, 229); box-sizing: border-box; color: #e74c3c; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; max-width: 100%; overflow-x: auto; padding: 2px 5px;&quot;&gt;&lt;span class=&quot;pre&quot; style=&quot;box-sizing: border-box;&quot;&gt;pip&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot; style=&quot;box-sizing: border-box;&quot;&gt;list&lt;/span&gt;&lt;/code&gt;의 경우는 pip나 setuptools같은 기본적으로 깔려 있는 패키지까지 출력을 해주고,&lt;/p&gt;&lt;div class=&quot;highlight-bash notranslate&quot; style=&quot;border: 1px solid rgb(225, 228, 229); box-sizing: border-box; margin: 1px 0px 24px; overflow-x: auto;&quot;&gt;&lt;div class=&quot;highlight&quot; style=&quot;background: rgb(248, 248, 248); border: none; box-sizing: border-box; margin: 0px; overflow-x: auto; padding: 0px;&quot;&gt;&lt;pre style=&quot;box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; line-height: 1.4; margin-bottom: 0px; margin-top: 0px; overflow: auto; padding: 12px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;&quot;&gt;&lt;/span&gt;&amp;gt;&amp;gt; pip list  
Package    Version
---------- -------
pip        &lt;span class=&quot;m&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;22&lt;/span&gt;.0.2
setuptools &lt;span class=&quot;m&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;59&lt;/span&gt;.6.0
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/section&gt;&lt;section id=&quot;id3&quot; style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px;&quot;&gt;
  &lt;h2 style=&quot;box-sizing: border-box; font-family: &amp;quot;Roboto Slab&amp;quot;, ff-tisa-web-pro, Georgia, Arial, sans-serif; font-size: 24px; margin-bottom: 24px; margin-top: 0px;&quot;&gt;패키지 설치&lt;/h2&gt;
  &lt;p style=&quot;box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;다음 명령어로는 깔려있는 패키지들을 requirement.txt 파일에 저장을 합니다.&lt;/p&gt;&lt;div class=&quot;highlight-bash notranslate&quot; style=&quot;border: 1px solid rgb(225, 228, 229); box-sizing: border-box; margin: 1px 0px 24px; overflow-x: auto;&quot;&gt;&lt;div class=&quot;highlight&quot; style=&quot;background: rgb(248, 248, 248); border: none; box-sizing: border-box; margin: 0px; overflow-x: auto; padding: 0px;&quot;&gt;&lt;pre style=&quot;box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; line-height: 1.4; margin-bottom: 0px; margin-top: 0px; overflow: auto; padding: 12px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;(&lt;/span&gt;env1&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;)&lt;/span&gt;&amp;gt;&amp;gt; pip freeze &amp;gt; requirement.txt
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p style=&quot;box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;&lt;code class=&quot;docutils literal notranslate&quot; style=&quot;background: rgb(255, 255, 255); border: 1px solid rgb(225, 228, 229); box-sizing: border-box; color: #e74c3c; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; max-width: 100%; overflow-x: auto; padding: 2px 5px;&quot;&gt;&lt;span class=&quot;pre&quot; style=&quot;box-sizing: border-box;&quot;&gt;-r&lt;/span&gt;&lt;/code&gt;&amp;nbsp;또는&amp;nbsp;&lt;code class=&quot;docutils literal notranslate&quot; style=&quot;background: rgb(255, 255, 255); border: 1px solid rgb(225, 228, 229); box-sizing: border-box; color: #e74c3c; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; max-width: 100%; overflow-x: auto; padding: 2px 5px;&quot;&gt;&lt;span class=&quot;pre&quot; style=&quot;box-sizing: border-box;&quot;&gt;--requirement&lt;/span&gt;&lt;/code&gt;&amp;nbsp;옵션을 사용하면, requirement.txt 파일에 있는 패키지들을 설치할 수 있습니다.&lt;/p&gt;&lt;div class=&quot;highlight-bash notranslate&quot; style=&quot;border: 1px solid rgb(225, 228, 229); box-sizing: border-box; margin: 1px 0px 24px; overflow-x: auto;&quot;&gt;&lt;div class=&quot;highlight&quot; style=&quot;background: rgb(248, 248, 248); border: none; box-sizing: border-box; margin: 0px; overflow-x: auto; padding: 0px;&quot;&gt;&lt;pre style=&quot;box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; line-height: 1.4; margin-bottom: 0px; margin-top: 0px; overflow: auto; padding: 12px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;(&lt;/span&gt;env1&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;)&lt;/span&gt;&amp;gt;&amp;gt; pip install -r requirement.txt 
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p style=&quot;box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;또 예제로, 아래와 같이 django 패키지를 설치할 수 있습니다.&lt;/p&gt;&lt;div class=&quot;highlight-bash notranslate&quot; style=&quot;border: 1px solid rgb(225, 228, 229); box-sizing: border-box; margin: 1px 0px 24px; overflow-x: auto;&quot;&gt;&lt;div class=&quot;highlight&quot; style=&quot;background: rgb(248, 248, 248); border: none; box-sizing: border-box; margin: 0px; overflow-x: auto; padding: 0px;&quot;&gt;&lt;pre style=&quot;box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; line-height: 1.4; margin-bottom: 0px; margin-top: 0px; overflow: auto; padding: 12px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;(&lt;/span&gt;env1&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;)&lt;/span&gt;&amp;gt;&amp;gt; pip install django 
&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;(&lt;/span&gt;env1&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;)&lt;/span&gt;&amp;gt;&amp;gt; pip freeze
&lt;span class=&quot;nv&quot; style=&quot;box-sizing: border-box; color: #19177c;&quot;&gt;asgiref&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;m&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;3&lt;/span&gt;.5.2
&lt;span class=&quot;nv&quot; style=&quot;box-sizing: border-box; color: #19177c;&quot;&gt;Django&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;m&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;4&lt;/span&gt;.1.3
&lt;span class=&quot;nv&quot; style=&quot;box-sizing: border-box; color: #19177c;&quot;&gt;sqlparse&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;m&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;0&lt;/span&gt;.4.3
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/section&gt;&lt;section id=&quot;id4&quot; style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px;&quot;&gt;&lt;h2 style=&quot;box-sizing: border-box; font-family: &amp;quot;Roboto Slab&amp;quot;, ff-tisa-web-pro, Georgia, Arial, sans-serif; font-size: 24px; margin-bottom: 24px; margin-top: 0px;&quot;&gt;패키지 삭제&lt;/h2&gt;&lt;p style=&quot;box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;&lt;code class=&quot;docutils literal notranslate&quot; style=&quot;background: rgb(255, 255, 255); border: 1px solid rgb(225, 228, 229); box-sizing: border-box; color: #e74c3c; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; max-width: 100%; overflow-x: auto; padding: 2px 5px;&quot;&gt;&lt;span class=&quot;pre&quot; style=&quot;box-sizing: border-box;&quot;&gt;pip&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot; style=&quot;box-sizing: border-box;&quot;&gt;uninstall&lt;/span&gt;&lt;/code&gt;&amp;nbsp;명령어를 이용하면 관련 패키지를 삭제할 수 있습니다. 즉, 다음과 같이 하면 관련 패키지들을 삭제할 수 있습니다.&lt;/p&gt;&lt;div class=&quot;highlight-bash notranslate&quot; style=&quot;border: 1px solid rgb(225, 228, 229); box-sizing: border-box; margin: 1px 0px 24px; overflow-x: auto;&quot;&gt;&lt;div class=&quot;highlight&quot; style=&quot;background: rgb(248, 248, 248); border: none; box-sizing: border-box; margin: 0px; overflow-x: auto; padding: 0px;&quot;&gt;&lt;pre style=&quot;box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; line-height: 1.4; margin-bottom: 0px; margin-top: 0px; overflow: auto; padding: 12px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;(&lt;/span&gt;env1&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;)&lt;/span&gt;&amp;gt;&amp;gt; pip freeze &amp;gt; requirement.txt
&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;(&lt;/span&gt;env1&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;)&lt;/span&gt;&amp;gt;&amp;gt; pip uninstall -r requirement.txt
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/section&gt;&lt;section id=&quot;offline&quot; style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px;&quot;&gt;&lt;h2 style=&quot;box-sizing: border-box; font-family: &amp;quot;Roboto Slab&amp;quot;, ff-tisa-web-pro, Georgia, Arial, sans-serif; font-size: 24px; margin-bottom: 24px; margin-top: 0px;&quot;&gt;offline 설치&lt;/h2&gt;&lt;p style=&quot;box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;그리고 사내망 같은 부분은 분리되어 있는 경우들이 있기때문에 offline 설치 방법이 필요합니다.&lt;/p&gt;&lt;section id=&quot;id5&quot; style=&quot;box-sizing: border-box;&quot;&gt;&lt;h3 style=&quot;box-sizing: border-box; font-family: &amp;quot;Roboto Slab&amp;quot;, ff-tisa-web-pro, Georgia, Arial, sans-serif; font-size: 20px; margin-bottom: 24px; margin-top: 0px;&quot;&gt;패키지 다운로드&lt;/h3&gt;&lt;p style=&quot;box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;먼저 외부망에서&amp;nbsp;&lt;code class=&quot;docutils literal notranslate&quot; style=&quot;background: rgb(255, 255, 255); border: 1px solid rgb(225, 228, 229); box-sizing: border-box; color: #e74c3c; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; max-width: 100%; overflow-x: auto; padding: 2px 5px;&quot;&gt;&lt;span class=&quot;pre&quot; style=&quot;box-sizing: border-box;&quot;&gt;pip&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot; style=&quot;box-sizing: border-box;&quot;&gt;download&lt;/span&gt;&lt;/code&gt;&amp;nbsp;명령어를 이용하면 패키지를 다운로드 받을 수 있습니다. 아래와 같이 django 패키지를 다운로드 받아 봅니다 whl 파일들이 다운된 것을 확인할 수 있습니다.&lt;/p&gt;&lt;div class=&quot;highlight-bash notranslate&quot; style=&quot;border: 1px solid rgb(225, 228, 229); box-sizing: border-box; margin: 1px 0px 24px; overflow-x: auto;&quot;&gt;&lt;div class=&quot;highlight&quot; style=&quot;background: rgb(248, 248, 248); border: none; box-sizing: border-box; margin: 0px; overflow-x: auto; padding: 0px;&quot;&gt;&lt;pre style=&quot;box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; line-height: 1.4; margin-bottom: 0px; margin-top: 0px; overflow: auto; padding: 12px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;(&lt;/span&gt;env1&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;)&lt;/span&gt;&amp;gt;&amp;gt; pip download django 
&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;(&lt;/span&gt;env1&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;)&lt;/span&gt;&amp;gt;&amp;gt; ls
Django-4.1.3-py3-none-any.whl
asgiref-3.5.2-py3-none-any.whl
sqlparse-0.4.3-py3-none-any.whl
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/section&gt;&lt;section id=&quot;id6&quot; style=&quot;box-sizing: border-box;&quot;&gt;&lt;h3 style=&quot;box-sizing: border-box; font-family: &amp;quot;Roboto Slab&amp;quot;, ff-tisa-web-pro, Georgia, Arial, sans-serif; font-size: 20px; margin-bottom: 24px; margin-top: 0px;&quot;&gt;패키지 로컬 설치&lt;/h3&gt;&lt;p style=&quot;box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;이 whl 파일들을 이용해서 다음 명령어를 사용하면 패키지들이 설치가 됩니다 -f 옵션은 whl 파일이 있는 위치를 나타냅니다.&lt;/p&gt;&lt;div class=&quot;highlight-bash notranslate&quot; style=&quot;border: 1px solid rgb(225, 228, 229); box-sizing: border-box; margin: 1px 0px 24px; overflow-x: auto;&quot;&gt;&lt;div class=&quot;highlight&quot; style=&quot;background: rgb(248, 248, 248); border: none; box-sizing: border-box; margin: 0px; overflow-x: auto; padding: 0px;&quot;&gt;&lt;pre style=&quot;box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; line-height: 1.4; margin-bottom: 0px; margin-top: 0px; overflow: auto; padding: 12px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;(&lt;/span&gt;env1&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;)&lt;/span&gt;&amp;gt;&amp;gt; pip install --no-index -f . django
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/section&gt;&lt;/section&gt;&lt;section id=&quot;id7&quot; style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px;&quot;&gt;&lt;h2 style=&quot;box-sizing: border-box; font-family: &amp;quot;Roboto Slab&amp;quot;, ff-tisa-web-pro, Georgia, Arial, sans-serif; font-size: 24px; margin-bottom: 24px; margin-top: 0px;&quot;&gt;마무리하며&lt;/h2&gt;&lt;p style=&quot;box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;이글을 처음 작성할 때는 python2 시절이었습니다. 그 당시에는 virtualenv, venv 와 같이 비슷한 이름의 패키지가 있어서, 헷갈리는 부분도 많았는데, 현재는 대부분 python3으로 대세가 넘어왔기 때문에 venv기준으로 내용을 정리 해 보았습니다.&lt;/p&gt;&lt;/section&gt;</content><link rel='replies' type='application/atom+xml' href='http://pyengine.blogspot.com/feeds/5969504011144756951/comments/default' title='댓글'/><link rel='replies' type='text/html' href='http://pyengine.blogspot.com/2019/12/python-virtual-environment-venv.html#comment-form' title='0개의 덧글'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4881868893095669586/posts/default/5969504011144756951'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4881868893095669586/posts/default/5969504011144756951'/><link rel='alternate' type='text/html' href='http://pyengine.blogspot.com/2019/12/python-virtual-environment-venv.html' title='Python venv(virtual Environment) 오프라인 설치'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4881868893095669586.post-8741475862895003686</id><published>2022-11-14T08:00:00.011+09:00</published><updated>2022-11-19T01:46:44.655+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="lstrip"/><category scheme="http://www.blogger.com/atom/ns#" term="removeprefix"/><category scheme="http://www.blogger.com/atom/ns#" term="removesuffix"/><category scheme="http://www.blogger.com/atom/ns#" term="rstrip&#xa;대안"/><category scheme="http://www.blogger.com/atom/ns#" term="파이썬 3.9"/><title type='text'>파이썬 removeprefix, removesuffix 와 lstrip, rstrip (3.9이상)</title><content type='html'>&lt;h1 style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: Nanum Myeongjo;&quot;&gt;removeprefix, removefix&lt;/span&gt;&lt;/h1&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Nanum Myeongjo&amp;quot;;&quot;&gt;파이썬 3.9에서 removeprefix와 removeprefix 함수가 추가 되었습니다. 
  얼핏보면 이 함수들은 기존의 lstrip과 rstrip함수와 달라보이지는 않습니다.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: Nanum Myeongjo;&quot;&gt;
그런데 이 strip함수는 하나만 잘라내는게 아니라 전부 잘라냅니다. 
  아래의 예제를 보시면 이해가 쉽습니다. &lt;/span&gt;&lt;/p&gt;



&lt;pre class=&quot;prettyprint lang-python&quot;&gt;
s = &#39;xyzxyzxyzxyz123123&#39;
print (s.lstrip(&#39;xyz&#39;))
print (s.removeprefix(&#39;xyz&#39;))

print (s.rstrip(&#39;123&#39;))
print (s.removesuffix(&#39;123&#39;))

# 123123123
# xyzxyzxyz123123123

# xyzxyzxyzxyz
# xyzxyzxyzxyz123123

&lt;/pre&gt;

&lt;p&gt;
strip함수는 1번만 잘라내는게 아니라 전부 잘라내기 때문에 의도와는 다르게 쓰일 수 있습니다. 

그렇다면 파이썬 3.9이하에서는 어떻게 할까요?&amp;nbsp;&lt;/p&gt;&lt;p&gt;startswith와 endswith함수로 확인하고, [:] 함수를 이용해서 해당 부분만 잘라냅니다. 
  조금 번거롭지만 위 함수들을 이용하면, 동일한 효과를 얻을 수가 있습니다. &lt;/p&gt;



&lt;pre class=&quot;prettyprint lang-python&quot;&gt;
def removeprefix_alt(text,prefix):
    if text.startswith(prefix):
        text_new = text[len(prefix):]
    else:
        text_new = text
    return text_new

def removesuffix_alt(text,suffix):
    if text.startswith(suffix):
        text_new = text[:-len(suffix)]
    else:
        text_new = text
    return text_new    

s = &#39;xyzxyzxyzxyz123123123&#39;
print (s.lstrip(&#39;xyz&#39;))
print (removeprefix_alt(s,&#39;xyz&#39;))
print (s.rstrip(&#39;123&#39;))
print (removesuffix_alt(s,&#39;xyz&#39;))

# prefix
# 123123123
# xyzxyzxyz123123123

# suffix
# xyzxyzxyzxyz
# xyzxyzxyzxyz123123
&lt;/pre&gt;


&lt;p&gt;
이상으로 파이썬 3.9에 추가된 removeprefix, removesuffix함수들을 정리 해 보았습니다
&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://pyengine.blogspot.com/feeds/8741475862895003686/comments/default' title='댓글'/><link rel='replies' type='text/html' href='http://pyengine.blogspot.com/2022/11/removeprefix-removesuffix-lstrip-rstrip.html#comment-form' title='0개의 덧글'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4881868893095669586/posts/default/8741475862895003686'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4881868893095669586/posts/default/8741475862895003686'/><link rel='alternate' type='text/html' href='http://pyengine.blogspot.com/2022/11/removeprefix-removesuffix-lstrip-rstrip.html' title='파이썬 removeprefix, removesuffix 와 lstrip, rstrip (3.9이상)'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4881868893095669586.post-1416007550091486451</id><published>2022-11-02T00:00:00.001+09:00</published><updated>2022-11-02T00:00:00.260+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="2차원"/><category scheme="http://www.blogger.com/atom/ns#" term="배열"/><category scheme="http://www.blogger.com/atom/ns#" term="생성&#xa;초기화"/><category scheme="http://www.blogger.com/atom/ns#" term="파이썬"/><title type='text'>파이썬 2차원 배열 생성 및 초기화</title><content type='html'>&lt;p&gt;&lt;span style=&quot;background-color: #fcfcfc; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px;&quot;&gt;파이썬에서 2차원 배열이 필요할 때가 있습니다. 그런데 2차원 배열은 리스트 컴프리헨션등으로 쉽게 만들어 낼 수가 있습니다. 다만, 여기서 하나 주의할 점이 있어서 그 부분만 집고 넘어가려고 합니다.&lt;/span&gt;&lt;/p&gt;&lt;section id=&quot;id1&quot; style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px;&quot;&gt;&lt;p style=&quot;box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;먼저, 2차원 배열은 화면에 그냥 뿌리면 보기 불편하니, 아래와 같이 2차원 배열을 뿌리는 함수를 먼저 만듭니다.&lt;/p&gt;&lt;div class=&quot;highlight-py notranslate&quot; style=&quot;border: 1px solid rgb(225, 228, 229); box-sizing: border-box; margin: 1px 0px 24px; overflow-x: auto;&quot;&gt;&lt;div class=&quot;highlight&quot; style=&quot;background: rgb(248, 248, 248); border: none; box-sizing: border-box; margin: 0px; overflow-x: auto; padding: 0px;&quot;&gt;&lt;pre style=&quot;box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; line-height: 1.4; margin-bottom: 0px; margin-top: 0px; overflow: auto; padding: 12px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;k&quot; style=&quot;box-sizing: border-box; color: green; font-weight: bold;&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot; style=&quot;box-sizing: border-box; color: blue;&quot;&gt;print_2d&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;k&quot; style=&quot;box-sizing: border-box; color: green; font-weight: bold;&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;row&lt;/span&gt; &lt;span class=&quot;ow&quot; style=&quot;box-sizing: border-box; color: #aa22ff; font-weight: bold;&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;k&quot; style=&quot;box-sizing: border-box; color: green; font-weight: bold;&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;c&lt;/span&gt; &lt;span class=&quot;ow&quot; style=&quot;box-sizing: border-box; color: #aa22ff; font-weight: bold;&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;row&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;end&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot; style=&quot;box-sizing: border-box; color: #ba2121;&quot;&gt;&#39; &#39;&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot; style=&quot;box-sizing: border-box; color: #ba2121;&quot;&gt;&#39;&#39;&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/section&gt;&lt;section id=&quot;for-2&quot; style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px;&quot;&gt;&lt;h2 style=&quot;box-sizing: border-box; font-family: &amp;quot;Roboto Slab&amp;quot;, ff-tisa-web-pro, Georgia, Arial, sans-serif; font-size: 24px; margin-bottom: 24px; margin-top: 0px;&quot;&gt;2중 for문으로 2중 리스트 선언&lt;/h2&gt;&lt;div class=&quot;highlight-py notranslate&quot; style=&quot;border: 1px solid rgb(225, 228, 229); box-sizing: border-box; margin: 1px 0px 24px; overflow-x: auto;&quot;&gt;&lt;div class=&quot;highlight&quot; style=&quot;background: rgb(248, 248, 248); border: none; box-sizing: border-box; margin: 0px; overflow-x: auto; padding: 0px;&quot;&gt;&lt;pre style=&quot;box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; line-height: 1.4; margin-bottom: 0px; margin-top: 0px; overflow: auto; padding: 12px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;ROW&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;COL&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;5&lt;/span&gt;
&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;arr&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;[[&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;k&quot; style=&quot;box-sizing: border-box; color: green; font-weight: bold;&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;c&lt;/span&gt; &lt;span class=&quot;ow&quot; style=&quot;box-sizing: border-box; color: #aa22ff; font-weight: bold;&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;COL&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;)]&lt;/span&gt; &lt;span class=&quot;k&quot; style=&quot;box-sizing: border-box; color: green; font-weight: bold;&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;row&lt;/span&gt; &lt;span class=&quot;ow&quot; style=&quot;box-sizing: border-box; color: #aa22ff; font-weight: bold;&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;ROW&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;)]&lt;/span&gt;
&lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;# 5x4 리스트를 생성합니다.  = (4열 5행) &lt;/span&gt;
&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;arr&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;9&lt;/span&gt; &lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;# (3, 2)에 값을 변경합니다. &lt;/span&gt;
&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;print_2d&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;arr&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;&#39;&#39;&#39;&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;0 0 0 0 0 &lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;0 0 0 0 0 &lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;0 0 0 9 0 &lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;0 0 0 0 0 &lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;&#39;&#39;&#39;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;section id=&quot;access&quot; style=&quot;box-sizing: border-box;&quot;&gt;&lt;h3 style=&quot;box-sizing: border-box; font-family: &amp;quot;Roboto Slab&amp;quot;, ff-tisa-web-pro, Georgia, Arial, sans-serif; font-size: 20px; margin-bottom: 24px; margin-top: 0px;&quot;&gt;2차원 배열 access&lt;a class=&quot;headerlink&quot; href=&quot;file://wsl.localhost/Ubuntu-22.04/home/student/works/sphinx/python/build/html/utility.html#access&quot; style=&quot;-webkit-font-smoothing: antialiased; box-sizing: border-box; color: #2980b9; cursor: pointer; display: inline-block; font-family: FontAwesome; font-size: 14px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; font-weight: normal; line-height: 1; margin-left: 0.5em; opacity: 0; text-decoration-line: none; text-rendering: auto;&quot; title=&quot;이 표제에 대한 퍼머링크&quot;&gt;&lt;/a&gt;&lt;/h3&gt;&lt;div class=&quot;highlight-py notranslate&quot; style=&quot;border: 1px solid rgb(225, 228, 229); box-sizing: border-box; margin: 1px 0px 24px; overflow-x: auto;&quot;&gt;&lt;div class=&quot;highlight&quot; style=&quot;background: rgb(248, 248, 248); border: none; box-sizing: border-box; margin: 0px; overflow-x: auto; padding: 0px;&quot;&gt;&lt;pre style=&quot;box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; line-height: 1.4; margin-bottom: 0px; margin-top: 0px; overflow: auto; padding: 12px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;# arr[row][col]&lt;/span&gt;
&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;arr&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;9&lt;/span&gt; 
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p style=&quot;box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;위와 같이 row가 앞쪽에 위치합니다. 이 부분도 은근히 헷갈릴 수 있으니 주의합시다.&lt;/p&gt;&lt;/section&gt;&lt;section id=&quot;for&quot; style=&quot;box-sizing: border-box;&quot;&gt;&lt;h3 style=&quot;box-sizing: border-box; font-family: &amp;quot;Roboto Slab&amp;quot;, ff-tisa-web-pro, Georgia, Arial, sans-serif; font-size: 20px; margin-bottom: 24px; margin-top: 0px;&quot;&gt;*연산자와 for문으로 리스트 선언&lt;/h3&gt;&lt;div class=&quot;highlight-py notranslate&quot; style=&quot;border: 1px solid rgb(225, 228, 229); box-sizing: border-box; margin: 1px 0px 24px; overflow-x: auto;&quot;&gt;&lt;div class=&quot;highlight&quot; style=&quot;background: rgb(248, 248, 248); border: none; box-sizing: border-box; margin: 0px; overflow-x: auto; padding: 0px;&quot;&gt;&lt;pre style=&quot;box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; line-height: 1.4; margin-bottom: 0px; margin-top: 0px; overflow: auto; padding: 12px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;arr&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;[[&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;5&lt;/span&gt; &lt;span class=&quot;k&quot; style=&quot;box-sizing: border-box; color: green; font-weight: bold;&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;ow&quot; style=&quot;box-sizing: border-box; color: #aa22ff; font-weight: bold;&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;)]&lt;/span&gt;
&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;arr&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;9&lt;/span&gt;
&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;print_2d&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;arr&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;&#39;&#39;&#39;&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;0 0 0 0 0 &lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;0 0 0 0 0 &lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;0 0 0 9 0 &lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;0 0 0 0 0 &lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;&#39;&#39;&#39;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/section&gt;&lt;section id=&quot;id2&quot; style=&quot;box-sizing: border-box;&quot;&gt;&lt;h3 style=&quot;box-sizing: border-box; font-family: &amp;quot;Roboto Slab&amp;quot;, ff-tisa-web-pro, Georgia, Arial, sans-serif; font-size: 20px; margin-bottom: 24px; margin-top: 0px;&quot;&gt;연산자 *로 2중 리스트 선언&lt;/h3&gt;&lt;div class=&quot;highlight-py notranslate&quot; style=&quot;border: 1px solid rgb(225, 228, 229); box-sizing: border-box; margin: 1px 0px 24px; overflow-x: auto;&quot;&gt;&lt;div class=&quot;highlight&quot; style=&quot;background: rgb(248, 248, 248); border: none; box-sizing: border-box; margin: 0px; overflow-x: auto; padding: 0px;&quot;&gt;&lt;pre style=&quot;box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; line-height: 1.4; margin-bottom: 0px; margin-top: 0px; overflow: auto; padding: 12px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;arr&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;[[&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;5&lt;/span&gt; &lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;4&lt;/span&gt;
&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;arr&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;9&lt;/span&gt;
&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;print_2d&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;arr&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;&#39;&#39;&#39;&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;0 0 0 9 0 &lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;0 0 0 9 0 &lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;0 0 0 9 0 &lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;0 0 0 9 0 &lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;&#39;&#39;&#39;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p style=&quot;box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;이 방법은 주의해야합니다. 위의 두 방법 말고 이 방법으로 배열을 선언하게 되면, row를 새로 생성하는것이 아니라. 단순히 요소를 복사하게 되는 얕은복사 (shallow copy)가 발생합니다. 즉, row의 첫번째 값의 링크로 만들어진 것이라 저런식으로 만들게 되면 어떤 값이든 바꿀때 마다 값이 같이 변경됩니다. 위 예제에서도 (3,2)를 변경했는데 모든 row가 같이 바뀐것을 확인할 수 가 있습니다.&lt;/p&gt;&lt;p style=&quot;box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;이러한 방식으로 선언 뒤에, 값을 변경하게되면 다른 원소들도 값이 변경되는 현상이 발생하게 되므로 이를 인지하고, 후에 대입연산자를 통해 값을 변경하지 않는 경우에만 사용하는것이 유리합니다. 그런데 위 방법은 그냥 쓰지 않는것을 추천합니다&lt;/p&gt;&lt;div class=&quot;highlight-py notranslate&quot; style=&quot;border: 1px solid rgb(225, 228, 229); box-sizing: border-box; margin: 1px 0px 24px; overflow-x: auto;&quot;&gt;&lt;div class=&quot;highlight&quot; style=&quot;background: rgb(248, 248, 248); border: none; box-sizing: border-box; margin: 0px; overflow-x: auto; padding: 0px;&quot;&gt;&lt;pre style=&quot;box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; line-height: 1.4; margin-bottom: 0px; margin-top: 0px; overflow: auto; padding: 12px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;10&lt;/span&gt;
&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;8&lt;/span&gt;
&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;# [0, 0, 0, 8, 0, 0, 0, 0, 0, 0]&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p style=&quot;box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;물론 1차원 배열을 생성할 때는 이런 shallow copy문제는 없습니다.&lt;/p&gt;&lt;/section&gt;&lt;/section&gt;</content><link rel='replies' type='application/atom+xml' href='http://pyengine.blogspot.com/feeds/1416007550091486451/comments/default' title='댓글'/><link rel='replies' type='text/html' href='http://pyengine.blogspot.com/2022/11/2.html#comment-form' title='0개의 덧글'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4881868893095669586/posts/default/1416007550091486451'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4881868893095669586/posts/default/1416007550091486451'/><link rel='alternate' type='text/html' href='http://pyengine.blogspot.com/2022/11/2.html' title='파이썬 2차원 배열 생성 및 초기화'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4881868893095669586.post-8567768835566985637</id><published>2022-10-26T00:00:00.001+09:00</published><updated>2022-10-26T00:00:00.177+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="dedent"/><category scheme="http://www.blogger.com/atom/ns#" term="indent"/><category scheme="http://www.blogger.com/atom/ns#" term="wrap"/><category scheme="http://www.blogger.com/atom/ns#" term="wraptext"/><category scheme="http://www.blogger.com/atom/ns#" term="파이썬"/><title type='text'>파이썬 textwrap (indent, 정렬, 줄바꿈)</title><content type='html'>&lt;p&gt;&amp;nbsp;&lt;span style=&quot;background-color: #fcfcfc; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px;&quot;&gt;이 textwrap 모듈은 텍스트를 핸들링할때 indentation을 넣거나 빼거나, 글자수를 터미널 너비에 맞춘다거나 할때 유용합니다. 즉, pretty-print가 필요한 경우, 텍스트를 핸들링할때 유용합니다. 많은 텍스트 편집기 및 워드 프로세서에서 볼 수 있는 단락 줄 바꿈 또는 채우기 기능과 유사한 프로그래밍 기능을 제공합니다.&lt;/span&gt;&lt;/p&gt;&lt;section id=&quot;filling-paragraphs&quot; style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px;&quot;&gt;&lt;h2 style=&quot;box-sizing: border-box; font-family: &amp;quot;Roboto Slab&amp;quot;, ff-tisa-web-pro, Georgia, Arial, sans-serif; font-size: 24px; margin-bottom: 24px; margin-top: 0px;&quot;&gt;Filling Paragraphs&lt;a class=&quot;headerlink&quot; href=&quot;file://wsl.localhost/Ubuntu-22.04/home/student/works/sphinx/python/build/html/textwrap.html#filling-paragraphs&quot; style=&quot;-webkit-font-smoothing: antialiased; box-sizing: border-box; color: #2980b9; cursor: pointer; display: inline-block; font-family: FontAwesome; font-size: 14px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; font-weight: normal; line-height: 1; margin-left: 0.5em; opacity: 0; text-decoration-line: none; text-rendering: auto;&quot; title=&quot;이 표제에 대한 퍼머링크&quot;&gt;&lt;/a&gt;&lt;/h2&gt;&lt;p style=&quot;box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;fill 함수에 대해 알아봅니다 fill() 함수는 텍스트를 width에 맞게 잘라주는 역할을 합니다.&lt;/p&gt;&lt;div class=&quot;highlight-py notranslate&quot; style=&quot;border: 1px solid rgb(225, 228, 229); box-sizing: border-box; margin: 1px 0px 24px; overflow-x: auto;&quot;&gt;&lt;div class=&quot;highlight&quot; style=&quot;background: rgb(248, 248, 248); border: none; box-sizing: border-box; margin: 0px; overflow-x: auto; padding: 0px;&quot;&gt;&lt;pre style=&quot;box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; line-height: 1.4; margin-bottom: 0px; margin-top: 0px; overflow: auto; padding: 12px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;# 실제 함수원형은 좀더 길지만, 아래 형태로 확인합니다&lt;/span&gt;
&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;textwrap&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;fill&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;str&lt;/span&gt; 
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;highlight-py notranslate&quot; style=&quot;border: 1px solid rgb(225, 228, 229); box-sizing: border-box; margin: 1px 0px 24px; overflow-x: auto;&quot;&gt;&lt;div class=&quot;highlight&quot; style=&quot;background: rgb(248, 248, 248); border: none; box-sizing: border-box; margin: 0px; overflow-x: auto; padding: 0px;&quot;&gt;&lt;pre style=&quot;box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; line-height: 1.4; margin-bottom: 0px; margin-top: 0px; overflow: auto; padding: 12px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kn&quot; style=&quot;box-sizing: border-box; color: green; font-weight: bold;&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot; style=&quot;box-sizing: border-box; color: blue; font-weight: bold;&quot;&gt;textwrap&lt;/span&gt;

&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;text&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot; style=&quot;box-sizing: border-box; color: #ba2121;&quot;&gt;&#39;&#39;&#39;&lt;/span&gt;
&lt;span class=&quot;s1&quot; style=&quot;box-sizing: border-box; color: #ba2121;&quot;&gt;    I have two sisters who have made their careers in engineering. My first sister has&lt;/span&gt;
&lt;span class=&quot;s1&quot; style=&quot;box-sizing: border-box; color: #ba2121;&quot;&gt;    a doctorate in civil engineering. She works in Australia designing mine tunnels for&lt;/span&gt;
&lt;span class=&quot;s1&quot; style=&quot;box-sizing: border-box; color: #ba2121;&quot;&gt;    a raw materials company. My second sister earned a master&#39;s degree in electrical&lt;/span&gt;
&lt;span class=&quot;s1&quot; style=&quot;box-sizing: border-box; color: #ba2121;&quot;&gt;    engineering. She works in the United States designing communication equipment.&lt;/span&gt;
&lt;span class=&quot;s1&quot; style=&quot;box-sizing: border-box; color: #ba2121;&quot;&gt;    In summary, my two sisters both have graduate degrees in engineering and have&lt;/span&gt;
&lt;span class=&quot;s1&quot; style=&quot;box-sizing: border-box; color: #ba2121;&quot;&gt;    careers in engineering.&lt;/span&gt;
&lt;span class=&quot;s1&quot; style=&quot;box-sizing: border-box; color: #ba2121;&quot;&gt;&#39;&#39;&#39;&lt;/span&gt;

&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;textwrap&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;fill&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;50&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;&#39;&#39;&#39;&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt; I have two sisters who have made their careers in&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;engineering. My first sister has a doctorate in&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;civil engineering. She works in Australia&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;designing mine tunnels for a raw materials&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;company. My second sister earned a master&#39;s degree&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;in electrical engineering. She works in the United&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;States designing communication equipment. In&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;summary, my two sisters both have graduate degrees&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;in engineering and have careers in engineering.&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;&#39;&#39;&#39;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p style=&quot;box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;이제 텍스트가 왼쪽 정렬되지만 첫 번째 줄은 들여쓰기를 유지하고 각 후속 줄의 앞부터 공백이 단락에 포함됩니다.&lt;/p&gt;&lt;p style=&quot;box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;textwrap 모듈은 예쁜 인쇄가 필요한 상황에서 출력할 텍스트의 형식을 지정하는 데 사용할 수 있습니다. 프로그래밍 방식을 제공합니다. 많은 텍스트 편집기에서 볼 수 있는 단락 줄 바꿈 또는 채우기 기능과 유사한 기능입니다.&lt;/p&gt;&lt;/section&gt;&lt;section id=&quot;indentation&quot; style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px;&quot;&gt;&lt;h2 style=&quot;box-sizing: border-box; font-family: &amp;quot;Roboto Slab&amp;quot;, ff-tisa-web-pro, Georgia, Arial, sans-serif; font-size: 24px; margin-bottom: 24px; margin-top: 0px;&quot;&gt;Indentation 제거&lt;/h2&gt;&lt;p style=&quot;box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;이전 예제에는 출력에 포함된 탭과 추가 공백이 포함되어 있으므로 형식이 매우 명확하지 않습니다. 샘플 텍스트의 모든 줄에서 공통 공백 접두사를 제거하면 더 나은 결과를 얻을 수 있으며 코드 서식 자체를 제거하면서 Python 코드에서 직접 독스트링 또는 포함된 여러 줄 문자열을 사용할 수 있습니다. 샘플 문자열에는 이 기능을 설명하기 위해 도입된 인위적인 들여쓰기 수준이 있습니다. dedent를 사용하면 공백을 제거해 줍니다.&lt;/p&gt;&lt;div class=&quot;highlight-py notranslate&quot; style=&quot;border: 1px solid rgb(225, 228, 229); box-sizing: border-box; margin: 1px 0px 24px; overflow-x: auto;&quot;&gt;&lt;div class=&quot;highlight&quot; style=&quot;background: rgb(248, 248, 248); border: none; box-sizing: border-box; margin: 0px; overflow-x: auto; padding: 0px;&quot;&gt;&lt;pre style=&quot;box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; line-height: 1.4; margin-bottom: 0px; margin-top: 0px; overflow: auto; padding: 12px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;&#39;&#39;&#39;&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;I have two sisters who have made their careers in engineering. My first sister has&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;a doctorate in civil engineering. She works in Australia designing mine tunnels for&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;a raw materials company. My second sister earned a master&#39;s degree in electrical&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;engineering. She works in the United States designing communication equipment.&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;In summary, my two sisters both have graduate degrees in engineering and have&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;careers in engineering.&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;&#39;&#39;&#39;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p style=&quot;box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;아래 예제도 참고 합니다. indent가 들쭉날쭉 한 경우에도 이 공백을 댕겨줍니다. 다만, 실제 paragraph상의 indent를 제거하지 않습니다.&lt;/p&gt;&lt;div class=&quot;highlight-py notranslate&quot; style=&quot;border: 1px solid rgb(225, 228, 229); box-sizing: border-box; margin: 1px 0px 24px; overflow-x: auto;&quot;&gt;&lt;div class=&quot;highlight&quot; style=&quot;background: rgb(248, 248, 248); border: none; box-sizing: border-box; margin: 0px; overflow-x: auto; padding: 0px;&quot;&gt;&lt;pre style=&quot;box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; line-height: 1.4; margin-bottom: 0px; margin-top: 0px; overflow: auto; padding: 12px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;text2&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot; style=&quot;box-sizing: border-box; color: #ba2121;&quot;&gt;&#39;&#39;&#39;&lt;/span&gt;
&lt;span class=&quot;s1&quot; style=&quot;box-sizing: border-box; color: #ba2121;&quot;&gt;        I have two sisters who have made their careers in engineering. My first sister has&lt;/span&gt;
&lt;span class=&quot;s1&quot; style=&quot;box-sizing: border-box; color: #ba2121;&quot;&gt;    a doctorate in civil engineering. She works in Australia designing mine tunnels for&lt;/span&gt;
&lt;span class=&quot;s1&quot; style=&quot;box-sizing: border-box; color: #ba2121;&quot;&gt;    a raw materials company. My second sister earned a master&#39;s degree in electrical&lt;/span&gt;
&lt;span class=&quot;s1&quot; style=&quot;box-sizing: border-box; color: #ba2121;&quot;&gt;    engineering. She works in the United States designing communication equipment.&lt;/span&gt;
&lt;span class=&quot;s1&quot; style=&quot;box-sizing: border-box; color: #ba2121;&quot;&gt;        In summary, my two sisters both have graduate degrees in engineering and have&lt;/span&gt;
&lt;span class=&quot;s1&quot; style=&quot;box-sizing: border-box; color: #ba2121;&quot;&gt;    careers in engineering.&lt;/span&gt;
&lt;span class=&quot;s1&quot; style=&quot;box-sizing: border-box; color: #ba2121;&quot;&gt;&#39;&#39;&#39;&lt;/span&gt;

&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;textwrap&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;dedent&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;text2&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;))&lt;/span&gt;

&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;&#39;&#39;&#39;&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;    I have two sisters who have made their careers in engineering. My first sister has&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;a doctorate in civil engineering. She works in Australia designing mine tunnels for&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;a raw materials company. My second sister earned a master&#39;s degree in electrical&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;engineering. She works in the United States designing communication equipment.&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;    In summary, my two sisters both have graduate degrees in engineering and have&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;careers in engineering.&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;&#39;&#39;&#39;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/section&gt;&lt;section id=&quot;dedent-fill&quot; style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px;&quot;&gt;&lt;h2 style=&quot;box-sizing: border-box; font-family: &amp;quot;Roboto Slab&amp;quot;, ff-tisa-web-pro, Georgia, Arial, sans-serif; font-size: 24px; margin-bottom: 24px; margin-top: 0px;&quot;&gt;Dedent 와 Fill 함수 조합&lt;/h2&gt;&lt;p style=&quot;box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;다음은 dedent된 텍스트를 fill로 맞추어 봅니다. 위의 Text2 예제를 그대로 씁니다. dedent로 공백을 걷어내고, strip() 으로 좌우 여백을 완전히 잘라줍니다. 그리고 fill을 사용하면 width에 맞게 다시 text가 정렬이 됩니다.&lt;/p&gt;&lt;div class=&quot;highlight-py notranslate&quot; style=&quot;border: 1px solid rgb(225, 228, 229); box-sizing: border-box; margin: 1px 0px 24px; overflow-x: auto;&quot;&gt;&lt;div class=&quot;highlight&quot; style=&quot;background: rgb(248, 248, 248); border: none; box-sizing: border-box; margin: 0px; overflow-x: auto; padding: 0px;&quot;&gt;&lt;pre style=&quot;box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; line-height: 1.4; margin-bottom: 0px; margin-top: 0px; overflow: auto; padding: 12px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;text3&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;textwrap&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;dedent&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;text2&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;strip&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;text4&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;textwrap&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;fill&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;text3&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;60&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;text4&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;&#39;&#39;&#39;&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;I have two sisters who have made their careers in&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;engineering. My first sister has a doctorate in civil&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;engineering. She works in Australia designing mine tunnels&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;for a raw materials company. My second sister earned a&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;master&#39;s degree in electrical engineering. She works in the&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;United States designing communication equipment.     In&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;summary, my two sisters both have graduate degrees in&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;engineering and have careers in engineering.&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;&#39;&#39;&#39;&lt;/span&gt;

&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/section&gt;&lt;section id=&quot;indents&quot; style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px;&quot;&gt;&lt;h2 style=&quot;box-sizing: border-box; font-family: &amp;quot;Roboto Slab&amp;quot;, ff-tisa-web-pro, Georgia, Arial, sans-serif; font-size: 24px; margin-bottom: 24px; margin-top: 0px;&quot;&gt;Indents&lt;a class=&quot;headerlink&quot; href=&quot;file://wsl.localhost/Ubuntu-22.04/home/student/works/sphinx/python/build/html/textwrap.html#indents&quot; style=&quot;-webkit-font-smoothing: antialiased; box-sizing: border-box; color: #2980b9; cursor: pointer; display: inline-block; font-family: FontAwesome; font-size: 14px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; font-weight: normal; line-height: 1; margin-left: 0.5em; opacity: 0; text-decoration-line: none; text-rendering: auto;&quot; title=&quot;이 표제에 대한 퍼머링크&quot;&gt;&lt;/a&gt;&lt;/h2&gt;&lt;p style=&quot;box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;때로는 문장 전체에 앞에 공백등을 넣어야 할때가 있습니다. 원래 문장에 4칸의 공백을 넣어봅니다.&lt;/p&gt;&lt;div class=&quot;highlight-py notranslate&quot; style=&quot;border: 1px solid rgb(225, 228, 229); box-sizing: border-box; margin: 1px 0px 24px; overflow-x: auto;&quot;&gt;&lt;div class=&quot;highlight&quot; style=&quot;background: rgb(248, 248, 248); border: none; box-sizing: border-box; margin: 0px; overflow-x: auto; padding: 0px;&quot;&gt;&lt;pre style=&quot;box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; line-height: 1.4; margin-bottom: 0px; margin-top: 0px; overflow: auto; padding: 12px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;text5&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s1&quot; style=&quot;box-sizing: border-box; color: #ba2121;&quot;&gt;&#39;&#39;&#39;&lt;/span&gt;
&lt;span class=&quot;s1&quot; style=&quot;box-sizing: border-box; color: #ba2121;&quot;&gt;I have two sisters who have made their careers in&lt;/span&gt;
&lt;span class=&quot;s1&quot; style=&quot;box-sizing: border-box; color: #ba2121;&quot;&gt;engineering. My first sister has a doctorate in civil&lt;/span&gt;
&lt;span class=&quot;s1&quot; style=&quot;box-sizing: border-box; color: #ba2121;&quot;&gt;engineering. She works in Australia designing mine tunnels&lt;/span&gt;
&lt;span class=&quot;s1&quot; style=&quot;box-sizing: border-box; color: #ba2121;&quot;&gt;for a raw materials company. My second sister earned a&lt;/span&gt;
&lt;span class=&quot;s1&quot; style=&quot;box-sizing: border-box; color: #ba2121;&quot;&gt;master&#39;s degree in electrical engineering. She works in the&lt;/span&gt;
&lt;span class=&quot;s1&quot; style=&quot;box-sizing: border-box; color: #ba2121;&quot;&gt;United States designing communication equipment.     In&lt;/span&gt;
&lt;span class=&quot;s1&quot; style=&quot;box-sizing: border-box; color: #ba2121;&quot;&gt;summary, my two sisters both have graduate degrees in&lt;/span&gt;
&lt;span class=&quot;s1&quot; style=&quot;box-sizing: border-box; color: #ba2121;&quot;&gt;engineering and have careers in engineering.&lt;/span&gt;
&lt;span class=&quot;s1&quot; style=&quot;box-sizing: border-box; color: #ba2121;&quot;&gt;&#39;&#39;&#39;&lt;/span&gt;
&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;textwrap&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;indent&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;text5&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s1&quot; style=&quot;box-sizing: border-box; color: #ba2121;&quot;&gt;&#39; &#39;&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;))&lt;/span&gt;

&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;&#39;&#39;&#39;&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;    I have two sisters who have made their careers in&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;    engineering. My first sister has a doctorate in civil&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;    engineering. She works in Australia designing mine tunnels&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;    for a raw materials company. My second sister earned a&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;    master&#39;s degree in electrical engineering. She works in the&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;    United States designing communication equipment.     In&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;    summary, my two sisters both have graduate degrees in&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;    engineering and have careers in engineering.&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;&#39;&#39;&#39;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p style=&quot;box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;위와 같이 indent가 잘 삽입되었습니다.&lt;/p&gt;&lt;p style=&quot;box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;이상으로 textwrap이 잘 동작 하는것을 확인해보았습니다. 이 textwrap은 종종 텍스트를 화면에 안잘리고 pretty-print하는 용도로 사용합니다.&lt;/p&gt;&lt;/section&gt;</content><link rel='replies' type='application/atom+xml' href='http://pyengine.blogspot.com/feeds/8567768835566985637/comments/default' title='댓글'/><link rel='replies' type='text/html' href='http://pyengine.blogspot.com/2022/10/textwrap-indent.html#comment-form' title='0개의 덧글'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4881868893095669586/posts/default/8567768835566985637'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4881868893095669586/posts/default/8567768835566985637'/><link rel='alternate' type='text/html' href='http://pyengine.blogspot.com/2022/10/textwrap-indent.html' title='파이썬 textwrap (indent, 정렬, 줄바꿈)'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4881868893095669586.post-5854787539627227607</id><published>2022-10-24T00:00:00.001+09:00</published><updated>2022-10-24T00:00:00.175+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="//"/><category scheme="http://www.blogger.com/atom/ns#" term="나눗셈"/><category scheme="http://www.blogger.com/atom/ns#" term="정수"/><category scheme="http://www.blogger.com/atom/ns#" term="퍄이썬"/><title type='text'>파이썬 정수 나눗셈 (/, // 차이)</title><content type='html'>&lt;p&gt;&amp;nbsp;&lt;span style=&quot;background-color: #fcfcfc; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px;&quot;&gt;이건 버젼별로 살짝 다른 부분이 있습니다. 파이썬 2.7에서 다음과 같이 나누기를 하면 나눗셈 연산이 버림을 기본으로 하는 정수 연산으로 수행이 됩니다. 정수끼리 나눗셈을 하면 정수를 리턴하고 , 실수가 중간에 끼어있으면 실수값이 리턴됩니다.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;이게 C와 비슷한데 정수끼리 나눗셈을 할 경우 기본적으로 정수로 가정해서 연산을 하고는 합니다. 실수형을 리턴받기 위해서는 아래와 같이 하나를 실수로 변경(2 -&amp;gt; 2.0)하면 결과값이 실수가 리턴이 됩니다.&lt;/p&gt;&lt;div class=&quot;highlight-py notranslate&quot; style=&quot;background-color: #fcfcfc; border: 1px solid rgb(225, 228, 229); box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; margin: 1px 0px 24px; overflow-x: auto;&quot;&gt;&lt;div class=&quot;highlight&quot; style=&quot;background: rgb(248, 248, 248); border: none; box-sizing: border-box; margin: 0px; overflow-x: auto; padding: 0px;&quot;&gt;&lt;pre style=&quot;box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; line-height: 1.4; margin-bottom: 0px; margin-top: 0px; overflow: auto; padding: 12px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;# python 2.7 &lt;/span&gt;
&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;4&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;2&lt;/span&gt; 
&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;# int&lt;/span&gt;
&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;4&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;mf&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;2.0&lt;/span&gt;
&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;mf&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;2.0&lt;/span&gt; &lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;# float&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;파이썬 3에서는&amp;nbsp;&lt;code class=&quot;docutils literal notranslate&quot; style=&quot;background: rgb(255, 255, 255); border: 1px solid rgb(225, 228, 229); box-sizing: border-box; color: #e74c3c; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; max-width: 100%; overflow-x: auto; padding: 2px 5px;&quot;&gt;&lt;span class=&quot;pre&quot; style=&quot;box-sizing: border-box;&quot;&gt;/&lt;/span&gt;&lt;/code&gt;&amp;nbsp;연산은&amp;nbsp;&lt;code class=&quot;docutils literal notranslate&quot; style=&quot;background: rgb(255, 255, 255); border: 1px solid rgb(225, 228, 229); box-sizing: border-box; color: #e74c3c; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; max-width: 100%; overflow-x: auto; padding: 2px 5px;&quot;&gt;&lt;span class=&quot;pre&quot; style=&quot;box-sizing: border-box;&quot;&gt;float&lt;/span&gt;&lt;/code&gt;&amp;nbsp;을 리턴합니다. 즉, 나눗셈연산이 기본적으로 실수연산으로 전환이 됩니다. 정수연산을 하기위해서는&amp;nbsp;&lt;code class=&quot;docutils literal notranslate&quot; style=&quot;background: rgb(255, 255, 255); border: 1px solid rgb(225, 228, 229); box-sizing: border-box; color: #e74c3c; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; max-width: 100%; overflow-x: auto; padding: 2px 5px;&quot;&gt;&lt;span class=&quot;pre&quot; style=&quot;box-sizing: border-box;&quot;&gt;//&lt;/span&gt;&lt;/code&gt;&amp;nbsp;을 사용해서 정수연산을 수행합니다.&lt;/p&gt;&lt;div class=&quot;highlight-py notranslate&quot; style=&quot;background-color: #fcfcfc; border: 1px solid rgb(225, 228, 229); box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; margin: 1px 0px 24px; overflow-x: auto;&quot;&gt;&lt;div class=&quot;highlight&quot; style=&quot;background: rgb(248, 248, 248); border: none; box-sizing: border-box; margin: 0px; overflow-x: auto; padding: 0px;&quot;&gt;&lt;pre style=&quot;box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; line-height: 1.4; margin-bottom: 0px; margin-top: 0px; overflow: auto; padding: 12px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;# python 3&lt;/span&gt;
&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;4&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;2&lt;/span&gt; 
&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;mf&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;2.0&lt;/span&gt; &lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;# float&lt;/span&gt;
&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;4&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;//&lt;/span&gt; &lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;2&lt;/span&gt;
&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;# int&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;&lt;code class=&quot;docutils literal notranslate&quot; style=&quot;background: rgb(255, 255, 255); border: 1px solid rgb(225, 228, 229); box-sizing: border-box; color: #e74c3c; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; max-width: 100%; overflow-x: auto; padding: 2px 5px;&quot;&gt;&lt;span class=&quot;pre&quot; style=&quot;box-sizing: border-box;&quot;&gt;/&lt;/span&gt;&lt;/code&gt;&amp;nbsp;연산자를 floating으로 전환 한다해도 정수연산이 필요한 경우가 여전히 존재하므로, 이때는&amp;nbsp;&lt;code class=&quot;docutils literal notranslate&quot; style=&quot;background: rgb(255, 255, 255); border: 1px solid rgb(225, 228, 229); box-sizing: border-box; color: #e74c3c; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; max-width: 100%; overflow-x: auto; padding: 2px 5px;&quot;&gt;&lt;span class=&quot;pre&quot; style=&quot;box-sizing: border-box;&quot;&gt;//&lt;/span&gt;&lt;/code&gt;로 정수 나눗셈연산으로 처리를 할 수가 있습니다.&lt;/p&gt;&lt;p style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;이걸 왜 구분해야하는냐 이&amp;nbsp;&lt;code class=&quot;docutils literal notranslate&quot; style=&quot;background: rgb(255, 255, 255); border: 1px solid rgb(225, 228, 229); box-sizing: border-box; color: #e74c3c; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; max-width: 100%; overflow-x: auto; padding: 2px 5px;&quot;&gt;&lt;span class=&quot;pre&quot; style=&quot;box-sizing: border-box;&quot;&gt;float&lt;/span&gt;&lt;/code&gt;&amp;nbsp;연산과&amp;nbsp;&lt;code class=&quot;docutils literal notranslate&quot; style=&quot;background: rgb(255, 255, 255); border: 1px solid rgb(225, 228, 229); box-sizing: border-box; color: #e74c3c; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; max-width: 100%; overflow-x: auto; padding: 2px 5px;&quot;&gt;&lt;span class=&quot;pre&quot; style=&quot;box-sizing: border-box;&quot;&gt;int&lt;/span&gt;&lt;/code&gt;&amp;nbsp;연산은 속도 차이가 좀 있습니다. 보통은 나눗셈연산이 오래 걸리기때문에, 정수로 처리할 수 있는 것들은 정수로 처리하는게 수행시간 측면에서 유리합니다 그리고 이런 나눗셈연산자는&amp;nbsp;&lt;code class=&quot;docutils literal notranslate&quot; style=&quot;background: rgb(255, 255, 255); border: 1px solid rgb(225, 228, 229); box-sizing: border-box; color: #e74c3c; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; max-width: 100%; overflow-x: auto; padding: 2px 5px;&quot;&gt;&lt;span class=&quot;pre&quot; style=&quot;box-sizing: border-box;&quot;&gt;%&lt;/span&gt;&lt;/code&gt;&amp;nbsp;와 같은 나머지 연산자와 보통 정수와 같이 핸들링하는 경우가 많습니다.&lt;/p&gt;&lt;p style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;그래서 이 차이를 알고 사용하는 것이 좀더 최적화된 구조를 만드는데 도움이 되리라 생각합니다.&lt;/p&gt;&lt;p style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;이번에는 정수 나눗셈연산에 정리해보았습니다. 이부분이 실제로 작성하다보면 종종 놓치는 부분이기도 하니, 이 정수 나눗셈이 버젼별로 다름을 살짝 인지하고 정수 나눗셈이랑 실수 나눗셈을 구분해서 사용하면 좋을듯합니다.&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://pyengine.blogspot.com/feeds/5854787539627227607/comments/default' title='댓글'/><link rel='replies' type='text/html' href='http://pyengine.blogspot.com/2022/10/blog-post.html#comment-form' title='0개의 덧글'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4881868893095669586/posts/default/5854787539627227607'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4881868893095669586/posts/default/5854787539627227607'/><link rel='alternate' type='text/html' href='http://pyengine.blogspot.com/2022/10/blog-post.html' title='파이썬 정수 나눗셈 (/, // 차이)'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4881868893095669586.post-7298420417692841320</id><published>2022-10-21T00:00:00.001+09:00</published><updated>2022-10-21T00:00:00.180+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="zfill"/><category scheme="http://www.blogger.com/atom/ns#" term="이진수"/><category scheme="http://www.blogger.com/atom/ns#" term="파이썬"/><title type='text'>파이썬 zfill 문자열 앞에 0 채우기 (이진수 만들기)</title><content type='html'>&lt;p style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;이 파이썬의 zfill함수는 이진수를 만들때 유용합니다. 뿐만 아니라, 전화번호나 날짜등을 표기할때도 유용합니다. 이번에는 주로 바이너리를 표현하는 방법에 관련해서적어 보려고 합니다.&lt;/p&gt;&lt;p style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;먼저 8을 이진수로 변경해봅니다.&lt;/p&gt;&lt;div class=&quot;highlight-py notranslate&quot; style=&quot;background-color: #fcfcfc; border: 1px solid rgb(225, 228, 229); box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; margin: 1px 0px 24px; overflow-x: auto;&quot;&gt;&lt;div class=&quot;highlight&quot; style=&quot;background: rgb(248, 248, 248); border: none; box-sizing: border-box; margin: 0px; overflow-x: auto; padding: 0px;&quot;&gt;&lt;pre style=&quot;box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; line-height: 1.4; margin-bottom: 0px; margin-top: 0px; overflow: auto; padding: 12px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;bin&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;# 0b1000&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;앞의 0b가 거슬립니다. 문자열이니 2번째 다음부터 가져오면 이진수만 떼어내 봅시다.&lt;/p&gt;&lt;div class=&quot;highlight-py notranslate&quot; style=&quot;background-color: #fcfcfc; border: 1px solid rgb(225, 228, 229); box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; margin: 1px 0px 24px; overflow-x: auto;&quot;&gt;&lt;div class=&quot;highlight&quot; style=&quot;background: rgb(248, 248, 248); border: none; box-sizing: border-box; margin: 0px; overflow-x: auto; padding: 0px;&quot;&gt;&lt;pre style=&quot;box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; line-height: 1.4; margin-bottom: 0px; margin-top: 0px; overflow: auto; padding: 12px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;bin&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;)[&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;:])&lt;/span&gt;
&lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;# 1000&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;이번엔 8이외에 여러 숫자들을 이진수로 바꾸어 봅니다.&lt;/p&gt;&lt;div class=&quot;highlight-py notranslate&quot; style=&quot;background-color: #fcfcfc; border: 1px solid rgb(225, 228, 229); box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; margin: 1px 0px 24px; overflow-x: auto;&quot;&gt;&lt;div class=&quot;highlight&quot; style=&quot;background: rgb(248, 248, 248); border: none; box-sizing: border-box; margin: 0px; overflow-x: auto; padding: 0px;&quot;&gt;&lt;pre style=&quot;box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; line-height: 1.4; margin-bottom: 0px; margin-top: 0px; overflow: auto; padding: 12px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;bin&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;)[&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;:])&lt;/span&gt;
&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;bin&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;)[&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;:])&lt;/span&gt;
&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;bin&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;)[&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;:])&lt;/span&gt;
&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;bin&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;)[&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;:])&lt;/span&gt;
&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;bin&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;)[&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;:])&lt;/span&gt;
&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;bin&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;)[&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;:])&lt;/span&gt;
&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;bin&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;)[&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;:])&lt;/span&gt;

&lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;# 0&lt;/span&gt;
&lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;# 1&lt;/span&gt;
&lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;# 10&lt;/span&gt;
&lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;# 11&lt;/span&gt;
&lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;# 110&lt;/span&gt;
&lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;# 111&lt;/span&gt;
&lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;# 1000&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;이진수가 만들어지지만, 뭔가 좀 비뚤빼뚤합니다. 이때 자리를 맞추기 위해서 zfill함수를 사용합니다.&lt;/p&gt;&lt;div class=&quot;highlight-py notranslate&quot; style=&quot;background-color: #fcfcfc; border: 1px solid rgb(225, 228, 229); box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; margin: 1px 0px 24px; overflow-x: auto;&quot;&gt;&lt;div class=&quot;highlight&quot; style=&quot;background: rgb(248, 248, 248); border: none; box-sizing: border-box; margin: 0px; overflow-x: auto; padding: 0px;&quot;&gt;&lt;pre style=&quot;box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; line-height: 1.4; margin-bottom: 0px; margin-top: 0px; overflow: auto; padding: 12px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;bin&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;)[&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;:]&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;zfill&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;bin&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;)[&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;:]&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;zfill&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;bin&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;)[&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;:]&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;zfill&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;bin&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;)[&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;:]&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;zfill&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;bin&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;)[&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;:]&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;zfill&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;bin&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;)[&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;:]&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;zfill&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;bin&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;)[&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;:]&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;zfill&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;))&lt;/span&gt;

&lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;# 0000&lt;/span&gt;
&lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;# 0001&lt;/span&gt;
&lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;# 0010&lt;/span&gt;
&lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;# 0011&lt;/span&gt;
&lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;# 0110&lt;/span&gt;
&lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;# 0111&lt;/span&gt;
&lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;# 1000&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;인제 뭔가 자리수가 맞는것 같습니다. 이렇게 표현하는 것이 뭔가 줄이 맞으니, 가독성면에서도 좋습니다 이 zfill 함수는 위와 같이 N자리 보다 작은 스트링을 앞쪽에 0을 붙여서 채웁니다.&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;background-color: #fcfcfc; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px;&quot;&gt;이 방법은 위와 같이 파이썬으로 이진수 표현할 때 유용합니다.&lt;/span&gt;&amp;nbsp;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://pyengine.blogspot.com/feeds/7298420417692841320/comments/default' title='댓글'/><link rel='replies' type='text/html' href='http://pyengine.blogspot.com/2022/10/zfill-0.html#comment-form' title='0개의 덧글'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4881868893095669586/posts/default/7298420417692841320'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4881868893095669586/posts/default/7298420417692841320'/><link rel='alternate' type='text/html' href='http://pyengine.blogspot.com/2022/10/zfill-0.html' title='파이썬 zfill 문자열 앞에 0 채우기 (이진수 만들기)'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4881868893095669586.post-6269924152250271790</id><published>2022-10-20T00:00:00.000+09:00</published><updated>2022-10-20T00:00:00.166+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="collections"/><category scheme="http://www.blogger.com/atom/ns#" term="Counter"/><category scheme="http://www.blogger.com/atom/ns#" term="파이썬"/><title type='text'>파이썬 collections Counter</title><content type='html'>&lt;h2 style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: &amp;quot;Roboto Slab&amp;quot;, ff-tisa-web-pro, Georgia, Arial, sans-serif; font-size: 24px; margin-bottom: 24px; margin-top: 0px;&quot;&gt;&lt;p style=&quot;box-sizing: border-box; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; font-weight: 400; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;Collection의 Counter 함수는 array나 list에 해당 값이 얼마나 나왔는지 세는 함수입니다.&lt;/p&gt;&lt;p style=&quot;box-sizing: border-box; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; font-weight: 400; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;이 Counter object는 사실 dictionary를 inherit 한것이라,, dictionary형태를 지니고 있습니다&lt;/p&gt;&lt;p style=&quot;box-sizing: border-box; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; font-weight: 400; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;아래는 예제입니다.&lt;/p&gt;&lt;div class=&quot;highlight-py notranslate&quot; style=&quot;border: 1px solid rgb(225, 228, 229); box-sizing: border-box; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; font-weight: 400; margin: 1px 0px 24px; overflow-x: auto;&quot;&gt;&lt;div class=&quot;highlight&quot; style=&quot;background: rgb(248, 248, 248); border: none; box-sizing: border-box; margin: 0px; overflow-x: auto; padding: 0px;&quot;&gt;&lt;pre style=&quot;box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; line-height: 1.4; margin-bottom: 0px; margin-top: 0px; overflow: auto; padding: 12px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kn&quot; style=&quot;box-sizing: border-box; color: green; font-weight: bold;&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot; style=&quot;box-sizing: border-box; color: blue; font-weight: bold;&quot;&gt;collections&lt;/span&gt; &lt;span class=&quot;kn&quot; style=&quot;box-sizing: border-box; color: green; font-weight: bold;&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;Counter&lt;/span&gt;
&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;sample&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;Counter&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;])&lt;/span&gt;
&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;sample&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;])&lt;/span&gt;  &lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;# 2&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p style=&quot;box-sizing: border-box; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; font-weight: 400; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;위 결과는 4의 개수를 센 값이 나옵니다.&lt;/p&gt;&lt;p style=&quot;box-sizing: border-box; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; font-weight: 400; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;Counter는 실제 excel같은데서 많이들 사용하는 함수와 같은 유형이라, 생각보다 유용한 경우가 많이 있습니다.&lt;/p&gt;&lt;/h2&gt;&lt;h3 style=&quot;box-sizing: border-box; font-family: &amp;quot;Roboto Slab&amp;quot;, ff-tisa-web-pro, Georgia, Arial, sans-serif; font-size: 20px; margin-bottom: 24px; margin-top: 0px;&quot;&gt;counter 함수를 사용해 리스트의 개수세기&lt;/h3&gt;&lt;h2 style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: &amp;quot;Roboto Slab&amp;quot;, ff-tisa-web-pro, Georgia, Arial, sans-serif; font-size: 24px; margin-bottom: 24px; margin-top: 0px;&quot;&gt;&lt;section id=&quot;counter&quot; style=&quot;box-sizing: border-box; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; font-weight: 400;&quot;&gt;&lt;p style=&quot;box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;collections.Counter(a) : a에서 요소들의 개수를 세어, 딕셔너리 형태로 반환합니다. {문자 : 개수} 형태&lt;/p&gt;&lt;div class=&quot;highlight-py notranslate&quot; style=&quot;border: 1px solid rgb(225, 228, 229); box-sizing: border-box; margin: 1px 0px 24px; overflow-x: auto;&quot;&gt;&lt;div class=&quot;highlight&quot; style=&quot;background: rgb(248, 248, 248); border: none; box-sizing: border-box; margin: 0px; overflow-x: auto; padding: 0px;&quot;&gt;&lt;pre style=&quot;box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; line-height: 1.4; margin-bottom: 0px; margin-top: 0px; overflow: auto; padding: 12px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kn&quot; style=&quot;box-sizing: border-box; color: green; font-weight: bold;&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot; style=&quot;box-sizing: border-box; color: blue; font-weight: bold;&quot;&gt;collections&lt;/span&gt;
&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;b&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;9&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;collections&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;Counter&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;collections&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;Counter&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;))&lt;/span&gt;

&lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;# Counter({3: 5, 2: 4, 1: 3, 4: 2, 5: 1}) Counter({3: 5, 2: 3, 1: 2, 4: 1, 5: 1, 9: 1})&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/section&gt;&lt;/h2&gt;&lt;h3 style=&quot;box-sizing: border-box; font-family: &amp;quot;Roboto Slab&amp;quot;, ff-tisa-web-pro, Georgia, Arial, sans-serif; font-size: 20px; margin-bottom: 24px; margin-top: 0px;&quot;&gt;counter - 연산&lt;a class=&quot;headerlink&quot; href=&quot;file://wsl.localhost/Ubuntu-22.04/home/student/works/sphinx/python/build/html/collections.html#id6&quot; style=&quot;-webkit-font-smoothing: antialiased; box-sizing: border-box; color: #2980b9; cursor: pointer; display: inline-block; font-family: FontAwesome; font-size: 14px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; font-weight: normal; line-height: 1; margin-left: 0.5em; opacity: 0; text-decoration-line: none; text-rendering: auto;&quot; title=&quot;이 표제에 대한 퍼머링크&quot;&gt;&lt;/a&gt;&lt;/h3&gt;&lt;h2 style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: &amp;quot;Roboto Slab&amp;quot;, ff-tisa-web-pro, Georgia, Arial, sans-serif; font-size: 24px; margin-bottom: 24px; margin-top: 0px;&quot;&gt;&lt;section id=&quot;id6&quot; style=&quot;box-sizing: border-box; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; font-weight: 400;&quot;&gt;&lt;p style=&quot;box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;counter 함수로 구한 딕셔너리의 값(value)끼리 연산이 가능합니다. 연산은 + , - , &amp;amp;(교집합), |(합집합) 네가지가 가능합니다. 서로 빼기 연산을 했을때 , 음수 값이 나오지는 않습니다. a list의 2, 3번이 나오지 않습니다&lt;/p&gt;&lt;div class=&quot;highlight-py notranslate&quot; style=&quot;border: 1px solid rgb(225, 228, 229); box-sizing: border-box; margin: 1px 0px 24px; overflow-x: auto;&quot;&gt;&lt;div class=&quot;highlight&quot; style=&quot;background: rgb(248, 248, 248); border: none; box-sizing: border-box; margin: 0px; overflow-x: auto; padding: 0px;&quot;&gt;&lt;pre style=&quot;box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; line-height: 1.4; margin-bottom: 0px; margin-top: 0px; overflow: auto; padding: 12px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kn&quot; style=&quot;box-sizing: border-box; color: green; font-weight: bold;&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot; style=&quot;box-sizing: border-box; color: blue; font-weight: bold;&quot;&gt;collections&lt;/span&gt;
&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;b&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;]&lt;/span&gt;

&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;collections&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;Counter&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;collections&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;Counter&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;collections&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;Counter&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;collections&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;Counter&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;collections&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;Counter&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;collections&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;Counter&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;collections&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;Counter&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;collections&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;Counter&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;))&lt;/span&gt;

&lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;# Counter({1: 4})&lt;/span&gt;
&lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;# Counter({1: 8, 2: 5, 3: 4})&lt;/span&gt;
&lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;# Counter({1: 2, 2: 1, 3: 1})&lt;/span&gt;
&lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;# Counter({1: 6, 2: 4, 3: 3})&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/section&gt;&lt;/h2&gt;&lt;h3 style=&quot;box-sizing: border-box; font-family: &amp;quot;Roboto Slab&amp;quot;, ff-tisa-web-pro, Georgia, Arial, sans-serif; font-size: 20px; margin-bottom: 24px; margin-top: 0px;&quot;&gt;most_common() 함수 - 최빈값 구하기&lt;a class=&quot;headerlink&quot; href=&quot;file://wsl.localhost/Ubuntu-22.04/home/student/works/sphinx/python/build/html/collections.html#most-common&quot; style=&quot;-webkit-font-smoothing: antialiased; box-sizing: border-box; color: #2980b9; cursor: pointer; display: inline-block; font-family: FontAwesome; font-size: 14px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; font-weight: normal; line-height: 1; margin-left: 0.5em; opacity: 0; text-decoration-line: none; text-rendering: auto;&quot; title=&quot;이 표제에 대한 퍼머링크&quot;&gt;&lt;/a&gt;&lt;/h3&gt;&lt;h2 style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: &amp;quot;Roboto Slab&amp;quot;, ff-tisa-web-pro, Georgia, Arial, sans-serif; font-size: 24px; margin-bottom: 24px; margin-top: 0px;&quot;&gt;&lt;section id=&quot;most-common&quot; style=&quot;box-sizing: border-box; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; font-weight: 400;&quot;&gt;&lt;p style=&quot;box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;most_common([n]) : 많이나오는 순서대로 상위부터 n개까지를 출력 (리스트에 담긴 튜플형태로)&lt;/p&gt;&lt;div class=&quot;highlight-py notranslate&quot; style=&quot;border: 1px solid rgb(225, 228, 229); box-sizing: border-box; margin: 1px 0px 24px; overflow-x: auto;&quot;&gt;&lt;div class=&quot;highlight&quot; style=&quot;background: rgb(248, 248, 248); border: none; box-sizing: border-box; margin: 0px; overflow-x: auto; padding: 0px;&quot;&gt;&lt;pre style=&quot;box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; line-height: 1.4; margin-bottom: 0px; margin-top: 0px; overflow: auto; padding: 12px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kn&quot; style=&quot;box-sizing: border-box; color: green; font-weight: bold;&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot; style=&quot;box-sizing: border-box; color: blue; font-weight: bold;&quot;&gt;collections&lt;/span&gt;
&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;a&lt;/span&gt;  &lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;45&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;9&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;]&lt;/span&gt;

&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;collections&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;Counter&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;most_common&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;))&lt;/span&gt;
 
&lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;# [(2, 5), (1, 4), (3, 2)]&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/section&gt;&lt;/h2&gt;&lt;h3 style=&quot;box-sizing: border-box; font-family: &amp;quot;Roboto Slab&amp;quot;, ff-tisa-web-pro, Georgia, Arial, sans-serif; font-size: 20px; margin-bottom: 24px; margin-top: 0px;&quot;&gt;elements() : 모든 element의 list를 출력&lt;a class=&quot;headerlink&quot; href=&quot;file://wsl.localhost/Ubuntu-22.04/home/student/works/sphinx/python/build/html/collections.html#elements-element-list&quot; style=&quot;-webkit-font-smoothing: antialiased; box-sizing: border-box; color: #2980b9; cursor: pointer; display: inline-block; font-family: FontAwesome; font-size: 14px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; font-weight: normal; line-height: 1; margin-left: 0.5em; opacity: 0; text-decoration-line: none; text-rendering: auto;&quot; title=&quot;이 표제에 대한 퍼머링크&quot;&gt;&lt;/a&gt;&lt;/h3&gt;&lt;h2 style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: &amp;quot;Roboto Slab&amp;quot;, ff-tisa-web-pro, Georgia, Arial, sans-serif; font-size: 24px; margin-bottom: 24px; margin-top: 0px;&quot;&gt;&lt;section id=&quot;elements-element-list&quot; style=&quot;box-sizing: border-box; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; font-weight: 400;&quot;&gt;&lt;div class=&quot;highlight-py notranslate&quot; style=&quot;border: 1px solid rgb(225, 228, 229); box-sizing: border-box; margin: 1px 0px 24px; overflow-x: auto;&quot;&gt;&lt;div class=&quot;highlight&quot; style=&quot;background: rgb(248, 248, 248); border: none; box-sizing: border-box; margin: 0px; overflow-x: auto; padding: 0px;&quot;&gt;&lt;pre style=&quot;box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; line-height: 1.4; margin-bottom: 0px; margin-top: 0px; overflow: auto; padding: 12px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kn&quot; style=&quot;box-sizing: border-box; color: green; font-weight: bold;&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot; style=&quot;box-sizing: border-box; color: blue; font-weight: bold;&quot;&gt;collections&lt;/span&gt;
&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;a&lt;/span&gt;  &lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;45&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;9&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;]&lt;/span&gt;

&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;list&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;collections&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;Counter&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;elements&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;()))&lt;/span&gt;
 
&lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;# [1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 4, 45, 9]&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p style=&quot;box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;이상으로 collections의 Counter 메소드들을 정리해보았습니다.&lt;/p&gt;&lt;/section&gt;&lt;/h2&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://pyengine.blogspot.com/feeds/6269924152250271790/comments/default' title='댓글'/><link rel='replies' type='text/html' href='http://pyengine.blogspot.com/2020/01/python-collections-counter.html#comment-form' title='0개의 덧글'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4881868893095669586/posts/default/6269924152250271790'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4881868893095669586/posts/default/6269924152250271790'/><link rel='alternate' type='text/html' href='http://pyengine.blogspot.com/2020/01/python-collections-counter.html' title='파이썬 collections Counter'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4881868893095669586.post-192572616689920491</id><published>2022-10-19T00:00:00.003+09:00</published><updated>2022-11-14T05:44:56.893+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="greedy"/><category scheme="http://www.blogger.com/atom/ns#" term="non greedy"/><category scheme="http://www.blogger.com/atom/ns#" term="regex"/><category scheme="http://www.blogger.com/atom/ns#" term="regular expression"/><category scheme="http://www.blogger.com/atom/ns#" term="정규식"/><category scheme="http://www.blogger.com/atom/ns#" term="최대"/><category scheme="http://www.blogger.com/atom/ns#" term="최소"/><category scheme="http://www.blogger.com/atom/ns#" term="탐욕"/><category scheme="http://www.blogger.com/atom/ns#" term="파이썬"/><title type='text'>파이썬 정규식, Greedy Non Greedy탐색(최소일치/최대일치)</title><content type='html'>&lt;p&gt;&amp;nbsp;&lt;span face=&quot;Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif&quot; style=&quot;background-color: #fcfcfc; color: #404040; font-size: 16px;&quot;&gt;이번엔 파이썬의 정규식(RegEx)중 Greedy match/Non-Greedy match부분을 설명합니다.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;아래와 같은 예제에서 첫번째 괄호만 매치를 시키자고 하고합니다.&lt;/p&gt;&lt;div class=&quot;highlight-default notranslate&quot; style=&quot;background-color: #fcfcfc; border: 1px solid rgb(225, 228, 229); box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; margin: 1px 0px 24px; overflow-x: auto;&quot;&gt;&lt;div class=&quot;highlight&quot; style=&quot;background: rgb(248, 248, 248); border: none; box-sizing: border-box; margin: 0px; overflow-x: auto; padding: 0px;&quot;&gt;&lt;pre style=&quot;box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; line-height: 1.4; margin-bottom: 0px; margin-top: 0px; overflow: auto; padding: 12px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;text&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot; style=&quot;box-sizing: border-box; color: #ba2121;&quot;&gt;&#39;(Machester 10) (London 20) (Seoul 30) (Tokyo 40)&#39;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;그렇지만, 실제로 아래와 같은 예제를 보면, 첫번째 괄호만 매치되는 게 아니라 마지막 괄호까지 전부 매치가 됩니다.&lt;/p&gt;&lt;p dir=&quot;ltr&quot; style=&quot;line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;&lt;span style=&quot;background-color: white; color: black; font-family: Arial; font-size: 13.999999999999998pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; white-space: pre;&quot;&gt;(.*) - Greedy match

&lt;/span&gt;&lt;/p&gt;&lt;p dir=&quot;ltr&quot; style=&quot;line-height: 1.2; margin-bottom: 0pt; margin-top: 0pt;&quot;&gt;&lt;span style=&quot;background-color: #a4c2f4; color: black; font-family: Arial; font-size: 13.999999999999998pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; white-space: pre;&quot;&gt;(Manchester 10) (London&amp;nbsp; 20) (Seoul 30) (Tokyo 40)&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;&lt;span style=&quot;color: black; font-family: Arial; font-size: 14pt; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;
(.*?) - Non Greedy match
&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: #a4c2f4; color: black; font-family: Arial; font-size: 14pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;
(Manchester 10)&lt;/span&gt;&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 14pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background-color: #a4c2f4; color: black; font-family: Arial; font-size: 14pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;(London&amp;nbsp; 20)&lt;/span&gt;&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 14pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background-color: #a4c2f4; color: black; font-family: Arial; font-size: 14pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;(Seoul 30)&lt;/span&gt;&lt;span style=&quot;background-color: transparent; color: black; font-family: Arial; font-size: 14pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background-color: #a4c2f4; color: black; font-family: Arial; font-size: 14pt; font-variant-east-asian: normal; font-variant-numeric: normal; vertical-align: baseline; white-space: pre-wrap;&quot;&gt;(Tokyo 40)&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;이것은 기본적으로 정규식은 Greedy match (최대한 많이 매치)를 하기 때문인데, 이렇게 되면 원래 의도와는 다른 결과가 나올 수 있습니다.&lt;/p&gt;&lt;p style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;그래서&amp;nbsp;&lt;code class=&quot;docutils literal notranslate&quot; style=&quot;background: rgb(255, 255, 255); border: 1px solid rgb(225, 228, 229); box-sizing: border-box; color: #e74c3c; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; max-width: 100%; overflow-x: auto; padding: 2px 5px;&quot;&gt;&lt;span class=&quot;pre&quot; style=&quot;box-sizing: border-box;&quot;&gt;.*&lt;/span&gt;&lt;/code&gt;&amp;nbsp;뒤에&amp;nbsp;&lt;code class=&quot;docutils literal notranslate&quot; style=&quot;background: rgb(255, 255, 255); border: 1px solid rgb(225, 228, 229); box-sizing: border-box; color: #e74c3c; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; max-width: 100%; overflow-x: auto; padding: 2px 5px;&quot;&gt;&lt;span class=&quot;pre&quot; style=&quot;box-sizing: border-box;&quot;&gt;?&lt;/span&gt;&lt;/code&gt;를 붙여서&amp;nbsp;&lt;code class=&quot;docutils literal notranslate&quot; style=&quot;background: rgb(255, 255, 255); border: 1px solid rgb(225, 228, 229); box-sizing: border-box; color: #e74c3c; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; max-width: 100%; overflow-x: auto; padding: 2px 5px;&quot;&gt;&lt;span class=&quot;pre&quot; style=&quot;box-sizing: border-box;&quot;&gt;.*?&lt;/span&gt;&lt;/code&gt;&amp;nbsp;과 같이 표현합니다. 그러면, 이 탐색자가 가장 많이 매치되는 경우를 찾아주는 것이 아니라 가장 적게 매치되는 경우를 찾아줍니다.&lt;/p&gt;&lt;div class=&quot;highlight-py notranslate&quot; style=&quot;background-color: #fcfcfc; border: 1px solid rgb(225, 228, 229); box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; margin: 1px 0px 24px; overflow-x: auto;&quot;&gt;&lt;div class=&quot;highlight&quot; style=&quot;background: rgb(248, 248, 248); border: none; box-sizing: border-box; margin: 0px; overflow-x: auto; padding: 0px;&quot;&gt;&lt;pre style=&quot;box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; line-height: 1.4; margin-bottom: 0px; margin-top: 0px; overflow: auto; padding: 12px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;text&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot; style=&quot;box-sizing: border-box; color: #ba2121;&quot;&gt;&#39;(Machester 10) (London 20) (Seoul 30) (Tokyo 40)&#39;&lt;/span&gt;
&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;re&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;compile&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot; style=&quot;box-sizing: border-box; color: #ba2121;&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;s1&quot; style=&quot;box-sizing: border-box; color: #ba2121;&quot;&gt;&#39;(\(.*\))&#39;&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot; style=&quot;box-sizing: border-box; color: green; font-weight: bold;&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;:=&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;search&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;):&lt;/span&gt; &lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;groups&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;())&lt;/span&gt; 
&lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;# (&#39;(Machester 10) (London 20) (Seoul 30) (Tokyo 40)&#39;,)&lt;/span&gt;

&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;re&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;compile&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sa&quot; style=&quot;box-sizing: border-box; color: #ba2121;&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;s1&quot; style=&quot;box-sizing: border-box; color: #ba2121;&quot;&gt;&#39;(\(.*?\))&#39;&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot; style=&quot;box-sizing: border-box; color: green; font-weight: bold;&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;:=&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;search&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;):&lt;/span&gt; &lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;groups&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;())&lt;/span&gt; 
&lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;# (&#39;(Machester 10)&#39;,)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;이런 예는 종종 볼수 있습니다. 이것 말고도 HTML, XML match시킬때도 마찬가지 입니다. 또, C-style 주석도 이런 경우 종종 볼수 있습니다.&amp;nbsp;&lt;code class=&quot;docutils literal notranslate&quot; style=&quot;background: rgb(255, 255, 255); border: 1px solid rgb(225, 228, 229); box-sizing: border-box; color: #e74c3c; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; max-width: 100%; overflow-x: auto; padding: 2px 5px;&quot;&gt;&lt;span class=&quot;pre&quot; style=&quot;box-sizing: border-box;&quot;&gt;/*&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;pre&quot; style=&quot;box-sizing: border-box;&quot;&gt;...&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;pre&quot; style=&quot;box-sizing: border-box;&quot;&gt;*/&lt;/span&gt;&lt;/code&gt;&amp;nbsp;와 같이 주석처리를 지우려고 하는데 , 텍스트 파일 전체가 지워지는 경우, 이 그리디매치가 적용이 되어서 그런것입니다.&lt;/p&gt;&lt;p style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;가장 가까운 괄호와 매치시키고 싶은데, 반복자가 최대한 많이 매치시키려 하기 때문에, 이런 부분의 차이를 알고 있다면 정규식 쓰는데 좀더 활용도를 높일 수가 있습니다.&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://pyengine.blogspot.com/feeds/192572616689920491/comments/default' title='댓글'/><link rel='replies' type='text/html' href='http://pyengine.blogspot.com/2022/10/greedynon-greedy.html#comment-form' title='0개의 덧글'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4881868893095669586/posts/default/192572616689920491'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4881868893095669586/posts/default/192572616689920491'/><link rel='alternate' type='text/html' href='http://pyengine.blogspot.com/2022/10/greedynon-greedy.html' title='파이썬 정규식, Greedy Non Greedy탐색(최소일치/최대일치)'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4881868893095669586.post-2490540458680947570</id><published>2022-10-17T07:00:00.005+09:00</published><updated>2022-10-17T07:00:00.167+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="class"/><category scheme="http://www.blogger.com/atom/ns#" term="iterable"/><category scheme="http://www.blogger.com/atom/ns#" term="iterator"/><category scheme="http://www.blogger.com/atom/ns#" term="python"/><category scheme="http://www.blogger.com/atom/ns#" term="이터레이터"/><title type='text'>파이썬 이터레이터 - 반복자 클래스</title><content type='html'>&lt;h1 style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: &amp;quot;Roboto Slab&amp;quot;, ff-tisa-web-pro, Georgia, Arial, sans-serif; font-size: 28px; margin-bottom: 24px; margin-top: 0px;&quot;&gt;&lt;br /&gt;&lt;/h1&gt;&lt;p style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;이번 주제는 파이썬 iterator입니다. 이터레이터는 번역한 것보면, 반복자라고도 하죠.&lt;br /&gt;이글은 이전에 작성하다가 나두었던 글인데, 다시 정리해서 올려봅니다&lt;/p&gt;&lt;p style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;파이썬에서 나오는 ~레이터, 이터레이터, 제네레이터, 데코레이터,, 이중에서 데코레이터는 앞에 두개랑 크게 상관이 없고요,&lt;/p&gt;&lt;p style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;&lt;em style=&quot;box-sizing: border-box;&quot;&gt;이터레이터&lt;/em&gt;&amp;nbsp;와&amp;nbsp;&lt;em style=&quot;box-sizing: border-box;&quot;&gt;제네레이터&lt;/em&gt;가 관련이 좀 있습니다.&lt;/p&gt;&lt;p style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;iterator를 이야기 하기전에 일단 iterable이라는 말을 집고 갑시다, iterable 이라는 의미는&amp;nbsp;&lt;span style=&quot;box-sizing: border-box; font-weight: 700;&quot;&gt;반복이 가능하다&lt;/span&gt;는 의미입니다.&lt;/p&gt;&lt;p style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;파이썬의 기본 데이터형인 리스트, 튜플, 딕셔너리등이 iterable이라고 합니다.&lt;/p&gt;&lt;p style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;그럼 이터레이터는?&lt;/p&gt;&lt;p style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;이것을 실제로 동작을 시키는 부분을 이터레이터라고 합니다, 리스트등을 이터레이터에 넣어서 데이터를 하나씩 빼내어 주는 용도 입니다,&lt;/p&gt;&lt;p style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;이터레이터는 기본적으로 design pattern에서 많이 사용되는 용어입니다&lt;/p&gt;&lt;p style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;우리가 어떤 반복문을 돌릴때, 이전에는 주로 for 문을 가지고 반복문을 만드는데, 이것을 좀 더 추상화, 일반화 시킨 개념이 이터레이터입니다, 예전에 C에서 반복문을 짤때는 다음과 같은식으로 시작을 했습니다&lt;/p&gt;&lt;div class=&quot;highlight-c notranslate&quot; style=&quot;background-color: #fcfcfc; border: 1px solid rgb(225, 228, 229); box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; margin: 1px 0px 24px; overflow-x: auto;&quot;&gt;&lt;div class=&quot;highlight&quot; style=&quot;background: rgb(248, 248, 248); border: none; box-sizing: border-box; margin: 0px; overflow-x: auto; padding: 0px;&quot;&gt;&lt;pre style=&quot;box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; line-height: 1.4; margin-bottom: 0px; margin-top: 0px; overflow: auto; padding: 12px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;w&quot; style=&quot;box-sizing: border-box; color: #bbbbbb;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;k&quot; style=&quot;box-sizing: border-box; color: green; font-weight: bold;&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;w&quot; style=&quot;box-sizing: border-box; color: #bbbbbb;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;w&quot; style=&quot;box-sizing: border-box; color: #bbbbbb;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;w&quot; style=&quot;box-sizing: border-box; color: #bbbbbb;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;w&quot; style=&quot;box-sizing: border-box; color: #bbbbbb;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;w&quot; style=&quot;box-sizing: border-box; color: #bbbbbb;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;w&quot; style=&quot;box-sizing: border-box; color: #bbbbbb;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;w&quot; style=&quot;box-sizing: border-box; color: #bbbbbb;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;w&quot; style=&quot;box-sizing: border-box; color: #bbbbbb;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;w&quot; style=&quot;box-sizing: border-box; color: #bbbbbb;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;w&quot; style=&quot;box-sizing: border-box; color: #bbbbbb;&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;w&quot; style=&quot;box-sizing: border-box; color: #bbbbbb;&quot;&gt; &lt;/span&gt;
&lt;span class=&quot;w&quot; style=&quot;box-sizing: border-box; color: #bbbbbb;&quot;&gt;     &lt;/span&gt;&lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;// action by array[i] &lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;이런식으로 명시적으로 반복문의 구조를 써줬는데,&lt;/p&gt;&lt;p style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;사이즈로 신경쓸필요 없이 item들을 가져다 달라는 구문입니다. 다른 언어중 foreach 로 시작하는 구문들이 이런 유사한 방식입니다 .&lt;/p&gt;&lt;p style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;부수적인 정보들 예를 들면, 사이즈등은 신경쓰고 싶지 않고, Array를 줄테니 알아서, 하나씩 빼줘 하는 개념이 이터레이터입니다.&lt;/p&gt;&lt;p style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;여기서 Array가 List, dictionary, tuple이 되는 것겠죠,&lt;/p&gt;&lt;p style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;이것이 꼭 정해진 data type이 아니라, 꼭 이 새로운 클래스에서도 iter함수를 구현하면, iterator를 사용할수 가 있습니다.&lt;/p&gt;&lt;p style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;꼭 배열이 아니라 집합이라든지, 어떤 object건 간에 iterator 를 호출하면, 미리 정의된대로 하나씩 불러오게 할 수 있습니다.&lt;/p&gt;&lt;p style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;어떤 큰단위가 있고, 하나씩 세부 아이템을 호출하는 용도입니다. 일반적으로 list, dictionary같은 형태는 for문에 넣으면 잘 동작합니다.&lt;/p&gt;&lt;p style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;아래와 같이 리스트, 딕셔너리, 스트링 전부 잘 이터레이션이 됩니다.&lt;/p&gt;&lt;div class=&quot;highlight-py notranslate&quot; style=&quot;background-color: #fcfcfc; border: 1px solid rgb(225, 228, 229); box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; margin: 1px 0px 24px; overflow-x: auto;&quot;&gt;&lt;div class=&quot;highlight&quot; style=&quot;background: rgb(248, 248, 248); border: none; box-sizing: border-box; margin: 0px; overflow-x: auto; padding: 0px;&quot;&gt;&lt;pre style=&quot;box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; line-height: 1.4; margin-bottom: 0px; margin-top: 0px; overflow: auto; padding: 12px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;k&quot; style=&quot;box-sizing: border-box; color: green; font-weight: bold;&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;ow&quot; style=&quot;box-sizing: border-box; color: #aa22ff; font-weight: bold;&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;]:&lt;/span&gt; &lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;# 리스트&lt;/span&gt;
    &lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot; style=&quot;box-sizing: border-box; color: green; font-weight: bold;&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;ow&quot; style=&quot;box-sizing: border-box; color: #aa22ff; font-weight: bold;&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;):&lt;/span&gt; &lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;# 튜플&lt;/span&gt;
    &lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot; style=&quot;box-sizing: border-box; color: green; font-weight: bold;&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;ow&quot; style=&quot;box-sizing: border-box; color: #aa22ff; font-weight: bold;&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;s1&quot; style=&quot;box-sizing: border-box; color: #ba2121;&quot;&gt;&#39;abc&#39;&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;# 문자열&lt;/span&gt;
    &lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;여기까지는 큰 문제 없이 몇번 사용하보면 이해가 쉬울것입니다.&lt;/p&gt;&lt;p style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;그러면, class에도 for문에 적용을 해보고 싶을때가 있습니다. 클래스를 이터러블하게 만드는 방법입니다.&amp;nbsp;&lt;span style=&quot;box-sizing: border-box; font-weight: 700;&quot;&gt;iter&lt;/span&gt;() 함수를 class 내부에 구현하는 방법입니다.&lt;/p&gt;&lt;p style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;next 와 StopIteration을 구현을 해줍니다. 이건 제네레이터에서도 나온 문법인데,&lt;/p&gt;&lt;p style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;먼저 next() 는 다음값을 구해주는 연산입니다. 그리고 StopIteration은 더이상 값이 없을때 호출해 줍니다.&lt;/p&gt;&lt;p style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;이런 식으로 iteration을 구현할 수 있습니다&lt;/p&gt;&lt;p style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;예제를 하나 알아봅니다. 무한 수열을 만들어봅니다. 리스트가 작으면 그냥 기입을 하면 되겠는데, 이 끝을 알수 없는 형태가 나오면, 무작정 나열할 수 가 없습니다.&lt;/p&gt;&lt;div class=&quot;highlight-py notranslate&quot; style=&quot;background-color: #fcfcfc; border: 1px solid rgb(225, 228, 229); box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; margin: 1px 0px 24px; overflow-x: auto;&quot;&gt;&lt;div class=&quot;highlight&quot; style=&quot;background: rgb(248, 248, 248); border: none; box-sizing: border-box; margin: 0px; overflow-x: auto; padding: 0px;&quot;&gt;&lt;pre style=&quot;box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; line-height: 1.4; margin-bottom: 0px; margin-top: 0px; overflow: auto; padding: 12px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;......&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,]&lt;/span&gt;  &lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;# fail&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;먼저아래와 같이 무한수열을 class로 선언해 줍니다.&lt;/p&gt;&lt;div class=&quot;highlight-py notranslate&quot; style=&quot;background-color: #fcfcfc; border: 1px solid rgb(225, 228, 229); box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; margin: 1px 0px 24px; overflow-x: auto;&quot;&gt;&lt;div class=&quot;highlight&quot; style=&quot;background: rgb(248, 248, 248); border: none; box-sizing: border-box; margin: 0px; overflow-x: auto; padding: 0px;&quot;&gt;&lt;pre style=&quot;box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; line-height: 1.4; margin-bottom: 0px; margin-top: 0px; overflow: auto; padding: 12px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;k&quot; style=&quot;box-sizing: border-box; color: green; font-weight: bold;&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot; style=&quot;box-sizing: border-box; color: blue; font-weight: bold;&quot;&gt;Infite&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;k&quot; style=&quot;box-sizing: border-box; color: green; font-weight: bold;&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;fm&quot; style=&quot;box-sizing: border-box; color: blue;&quot;&gt;__init__&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kc&quot; style=&quot;box-sizing: border-box; color: green; font-weight: bold;&quot;&gt;None&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;k&quot; style=&quot;box-sizing: border-box; color: green; font-weight: bold;&quot;&gt;pass&lt;/span&gt;

&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;Infite&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;()&lt;/span&gt;

&lt;span class=&quot;k&quot; style=&quot;box-sizing: border-box; color: green; font-weight: bold;&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;ow&quot; style=&quot;box-sizing: border-box; color: #aa22ff; font-weight: bold;&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;&#39;&#39;&#39;&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;Traceback (most recent call last):&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;  File &quot;infinite.py&quot;, line 10, in &amp;lt;module&amp;gt;&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;    for x in a:&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;TypeError: &#39;Infite&#39; object is not iterable&lt;/span&gt;
&lt;span class=&quot;sd&quot; style=&quot;box-sizing: border-box; color: #ba2121; font-style: italic;&quot;&gt;&#39;&#39;&#39;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;위 코드를 실행시키면 object가 iterable하지 않다고 에러가 납니다.&lt;/p&gt;&lt;p style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;이 클래스를 이터러블하게 만들어 봅니다. __iter__와 __next__를 추가해줍니다. __iter__는 iterable할때 초기화 시키는 함수라고 보면 되고, 아래는 직접 자기자신을 리턴하긴 했지만, 내부 리스트나 딕셔너리등을 리턴할 수도 있습니다. 여기서는 0으로 초기화 해줍니다. __next__에서는 리턴값을 더해줍니다. 내부 $self.cnt$에 +1하는 값을 더합니다. 이와 같이 구현할 경우, 종료값이 없으므로&amp;nbsp;&lt;span style=&quot;box-sizing: border-box; font-weight: 700;&quot;&gt;무한수열&lt;/span&gt;&amp;nbsp;입니다. 5에서 break를 걸었는데, break가 없으면 이 루프는 무한으로 동작합니다.&lt;/p&gt;&lt;div class=&quot;highlight-py notranslate&quot; style=&quot;background-color: #fcfcfc; border: 1px solid rgb(225, 228, 229); box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; margin: 1px 0px 24px; overflow-x: auto;&quot;&gt;&lt;div class=&quot;highlight&quot; style=&quot;background: rgb(248, 248, 248); border: none; box-sizing: border-box; margin: 0px; overflow-x: auto; padding: 0px;&quot;&gt;&lt;pre style=&quot;box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; line-height: 1.4; margin-bottom: 0px; margin-top: 0px; overflow: auto; padding: 12px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;k&quot; style=&quot;box-sizing: border-box; color: green; font-weight: bold;&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot; style=&quot;box-sizing: border-box; color: blue; font-weight: bold;&quot;&gt;Infite&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;k&quot; style=&quot;box-sizing: border-box; color: green; font-weight: bold;&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;fm&quot; style=&quot;box-sizing: border-box; color: blue;&quot;&gt;__init__&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kc&quot; style=&quot;box-sizing: border-box; color: green; font-weight: bold;&quot;&gt;None&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;bp&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;cnt&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;1&lt;/span&gt;
       
    &lt;span class=&quot;k&quot; style=&quot;box-sizing: border-box; color: green; font-weight: bold;&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;fm&quot; style=&quot;box-sizing: border-box; color: blue;&quot;&gt;__iter__&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;bp&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;cnt&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;0&lt;/span&gt;
        &lt;span class=&quot;k&quot; style=&quot;box-sizing: border-box; color: green; font-weight: bold;&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;bp&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;self&lt;/span&gt;
    &lt;span class=&quot;k&quot; style=&quot;box-sizing: border-box; color: green; font-weight: bold;&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;fm&quot; style=&quot;box-sizing: border-box; color: blue;&quot;&gt;__next__&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;bp&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;cnt&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;+=&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;1&lt;/span&gt;
        &lt;span class=&quot;k&quot; style=&quot;box-sizing: border-box; color: green; font-weight: bold;&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;bp&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;cnt&lt;/span&gt;

&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;Infite&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;()&lt;/span&gt;

&lt;span class=&quot;k&quot; style=&quot;box-sizing: border-box; color: green; font-weight: bold;&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;ow&quot; style=&quot;box-sizing: border-box; color: #aa22ff; font-weight: bold;&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;enumerate&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;end&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s1&quot; style=&quot;box-sizing: border-box; color: #ba2121;&quot;&gt;&#39; &#39;&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot; style=&quot;box-sizing: border-box; color: green; font-weight: bold;&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;k&quot; style=&quot;box-sizing: border-box; color: green; font-weight: bold;&quot;&gt;break&lt;/span&gt;
&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot; style=&quot;box-sizing: border-box; color: #ba2121;&quot;&gt;&#39;&#39;&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;# 1 2 3 4 5 6 &lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;여기서 next에 StopIteration을 추가해 봅니다. 아래와 같이 internal counter가 9에 도달할 경우, raise StopIteration을 호출해서, loop를 종료합니다. 실제로 무한루프가 돌면, 끝나지 않으니, 이런 식으로 종료를 시켜줄수 있겠죠. 아래 예제에서는 break구문없이 class내부에서 StopIteration을 호출해서, 마무리를 지어줍니다.&lt;/p&gt;&lt;div class=&quot;highlight-py notranslate&quot; style=&quot;background-color: #fcfcfc; border: 1px solid rgb(225, 228, 229); box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; margin: 1px 0px 24px; overflow-x: auto;&quot;&gt;&lt;div class=&quot;highlight&quot; style=&quot;background: rgb(248, 248, 248); border: none; box-sizing: border-box; margin: 0px; overflow-x: auto; padding: 0px;&quot;&gt;&lt;pre style=&quot;box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; line-height: 1.4; margin-bottom: 0px; margin-top: 0px; overflow: auto; padding: 12px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;k&quot; style=&quot;box-sizing: border-box; color: green; font-weight: bold;&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot; style=&quot;box-sizing: border-box; color: blue; font-weight: bold;&quot;&gt;Infite&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;k&quot; style=&quot;box-sizing: border-box; color: green; font-weight: bold;&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;fm&quot; style=&quot;box-sizing: border-box; color: blue;&quot;&gt;__init__&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kc&quot; style=&quot;box-sizing: border-box; color: green; font-weight: bold;&quot;&gt;None&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;bp&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;cnt&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;1&lt;/span&gt;
       
    &lt;span class=&quot;k&quot; style=&quot;box-sizing: border-box; color: green; font-weight: bold;&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;fm&quot; style=&quot;box-sizing: border-box; color: blue;&quot;&gt;__iter__&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;bp&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;cnt&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;0&lt;/span&gt;
        &lt;span class=&quot;k&quot; style=&quot;box-sizing: border-box; color: green; font-weight: bold;&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;bp&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;self&lt;/span&gt;
    &lt;span class=&quot;k&quot; style=&quot;box-sizing: border-box; color: green; font-weight: bold;&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;fm&quot; style=&quot;box-sizing: border-box; color: blue;&quot;&gt;__next__&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;bp&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;cnt&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;+=&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;1&lt;/span&gt;
        &lt;span class=&quot;k&quot; style=&quot;box-sizing: border-box; color: green; font-weight: bold;&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;bp&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;cnt&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;9&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;k&quot; style=&quot;box-sizing: border-box; color: green; font-weight: bold;&quot;&gt;raise&lt;/span&gt; &lt;span class=&quot;ne&quot; style=&quot;box-sizing: border-box; color: #cb3f38; font-weight: bold;&quot;&gt;StopIteration&lt;/span&gt;
        &lt;span class=&quot;k&quot; style=&quot;box-sizing: border-box; color: green; font-weight: bold;&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;bp&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;cnt&lt;/span&gt;

&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;Infite&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;()&lt;/span&gt;

&lt;span class=&quot;k&quot; style=&quot;box-sizing: border-box; color: green; font-weight: bold;&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;ow&quot; style=&quot;box-sizing: border-box; color: #aa22ff; font-weight: bold;&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;enumerate&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;end&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s1&quot; style=&quot;box-sizing: border-box; color: #ba2121;&quot;&gt;&#39; &#39;&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot; style=&quot;box-sizing: border-box; color: #ba2121;&quot;&gt;&#39;&#39;&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;# 1 2 3 4 5 6 7 8&lt;/span&gt;

&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;이상으로 이터레이션과 이터러블한 객체를 만드는 법을 정리해보았습니다. 위 예는 단순한 예이지만, 실제로 객체를 이터러블하게 만드는 방법은 실제로도 많이 쓰입니다. 이 내용을 참고하셔서 활용하시면 좋을것 같습니다.&lt;/p&gt;
&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://pyengine.blogspot.com/feeds/2490540458680947570/comments/default' title='댓글'/><link rel='replies' type='text/html' href='http://pyengine.blogspot.com/2017/12/python-iteratror.html#comment-form' title='0개의 덧글'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4881868893095669586/posts/default/2490540458680947570'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4881868893095669586/posts/default/2490540458680947570'/><link rel='alternate' type='text/html' href='http://pyengine.blogspot.com/2017/12/python-iteratror.html' title='파이썬 이터레이터 - 반복자 클래스'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4881868893095669586.post-6353266935373410554</id><published>2022-10-12T00:00:00.004+09:00</published><updated>2022-10-12T00:00:00.180+09:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="numpy"/><category scheme="http://www.blogger.com/atom/ns#" term="slicing"/><category scheme="http://www.blogger.com/atom/ns#" term="파이썬"/><title type='text'>Numpy Slicing</title><content type='html'>&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;슬라이싱을 사용하면 배열의 일부를 추출하여 새 배열을 생성할 수 있습니다. Python list를 사용하여 배열을 슬라이스 할 때 결과 배열은 copy이지만 NumPy에서 배열은 동일한 기본 버퍼의 참조입니다.&lt;/p&gt;&lt;p style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;슬라이싱이 numpy와 python이 약간 차이가 있습니다. 기본 파이썬의 경우는 slice를 할 경우 copy를 합니다. 즉, copy된 부분을 고쳐도 원본이 변경되지 않습니다. 그러나 numpy slice는 참조로 배열을 가져옵니다. 그 얘기는 slice된것을 수정할 경우, 원본도 같이 수정이 됩니다.&lt;/p&gt;&lt;div class=&quot;highlight-py notranslate&quot; style=&quot;background-color: #fcfcfc; border: 1px solid rgb(225, 228, 229); box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; margin: 1px 0px 24px; overflow-x: auto;&quot;&gt;&lt;div class=&quot;highlight&quot; style=&quot;background: rgb(248, 248, 248); border: none; box-sizing: border-box; margin: 0px; overflow-x: auto; padding: 0px;&quot;&gt;&lt;pre style=&quot;box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; line-height: 1.4; margin-bottom: 0px; margin-top: 0px; overflow: auto; padding: 12px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;# python기본 리스트로 생성합니다. &lt;/span&gt;
&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;b&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;# deep copy&lt;/span&gt;

&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;)&lt;/span&gt; 
&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;# [1, 2, 3, 4, 5]&lt;/span&gt;
&lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;# [3, 4]&lt;/span&gt;

&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;7&lt;/span&gt;
&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;# [1, 2, 3, 4, 5]&lt;/span&gt;
&lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;# [3, 7]&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;아래는 numpy case입니다.&lt;/p&gt;&lt;div class=&quot;highlight-py notranslate&quot; style=&quot;background-color: #fcfcfc; border: 1px solid rgb(225, 228, 229); box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; margin: 1px 0px 24px; overflow-x: auto;&quot;&gt;&lt;div class=&quot;highlight&quot; style=&quot;background: rgb(248, 248, 248); border: none; box-sizing: border-box; margin: 0px; overflow-x: auto; padding: 0px;&quot;&gt;&lt;pre style=&quot;box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; line-height: 1.4; margin-bottom: 0px; margin-top: 0px; overflow: auto; padding: 12px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;kn&quot; style=&quot;box-sizing: border-box; color: green; font-weight: bold;&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot; style=&quot;box-sizing: border-box; color: blue; font-weight: bold;&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot; style=&quot;box-sizing: border-box; color: green; font-weight: bold;&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;nn&quot; style=&quot;box-sizing: border-box; color: blue; font-weight: bold;&quot;&gt;np&lt;/span&gt;
&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;A&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;arange&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;)&lt;/span&gt;  &lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;# numpy method로 생성되어야합니다. &lt;/span&gt;

&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;B&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;# shallow copy &lt;/span&gt;
&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;B&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;# [1, 2, 3, 4, 5]&lt;/span&gt;
&lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;# [3, 4]&lt;/span&gt;

&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;B&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;7&lt;/span&gt;
&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nb&quot; style=&quot;box-sizing: border-box; color: green;&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;B&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;# [1, 2, 3, 7, 5]&lt;/span&gt;
&lt;span class=&quot;c1&quot; style=&quot;box-sizing: border-box; color: #3d7b7b; font-style: italic;&quot;&gt;# [3, 7]&lt;/span&gt;

&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;또, numpy slice는 step을 지원합니다. 배열의 일부만 추출할 수 있습니다. 아래와 같이 a[1:5:2]와 같은식으로 지정하면, for문 비슷하게 1부터 5까지 step 2만큼씩해서 리스트를 생성합니다.&lt;/p&gt;&lt;div class=&quot;highlight-py notranslate&quot; style=&quot;background-color: #fcfcfc; border: 1px solid rgb(225, 228, 229); box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; margin: 1px 0px 24px; overflow-x: auto;&quot;&gt;&lt;div class=&quot;highlight&quot; style=&quot;background: rgb(248, 248, 248); border: none; box-sizing: border-box; margin: 0px; overflow-x: auto; padding: 0px;&quot;&gt;&lt;pre style=&quot;box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; line-height: 1.4; margin-bottom: 0px; margin-top: 0px; overflow: auto; padding: 12px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;gp&quot; style=&quot;box-sizing: border-box; color: navy; font-weight: bold; pointer-events: none; user-select: none;&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;arange&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;16&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;gp&quot; style=&quot;box-sizing: border-box; color: navy; font-weight: bold; pointer-events: none; user-select: none;&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;a&lt;/span&gt;
&lt;span class=&quot;go&quot; style=&quot;box-sizing: border-box; color: #717171;&quot;&gt;array([10, 11, 12, 13, 14, 15])&lt;/span&gt;
&lt;span class=&quot;gp&quot; style=&quot;box-sizing: border-box; color: navy; font-weight: bold; pointer-events: none; user-select: none;&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;go&quot; style=&quot;box-sizing: border-box; color: #717171;&quot;&gt;array([11, 12, 13, 14])&lt;/span&gt;


&lt;span class=&quot;gp&quot; style=&quot;box-sizing: border-box; color: navy; font-weight: bold; pointer-events: none; user-select: none;&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;go&quot; style=&quot;box-sizing: border-box; color: #717171;&quot;&gt;array([11, 13])&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;이것에 대한 응용으로 아래와 같이도 사용할 수 있습니다.&lt;/p&gt;&lt;div class=&quot;highlight-py notranslate&quot; style=&quot;background-color: #fcfcfc; border: 1px solid rgb(225, 228, 229); box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; margin: 1px 0px 24px; overflow-x: auto;&quot;&gt;&lt;div class=&quot;highlight&quot; style=&quot;background: rgb(248, 248, 248); border: none; box-sizing: border-box; margin: 0px; overflow-x: auto; padding: 0px;&quot;&gt;&lt;pre style=&quot;box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; line-height: 1.4; margin-bottom: 0px; margin-top: 0px; overflow: auto; padding: 12px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;gp&quot; style=&quot;box-sizing: border-box; color: navy; font-weight: bold; pointer-events: none; user-select: none;&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;[::&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;go&quot; style=&quot;box-sizing: border-box; color: #717171;&quot;&gt;array([10, 12, 14])&lt;/span&gt;
&lt;span class=&quot;gp&quot; style=&quot;box-sizing: border-box; color: navy; font-weight: bold; pointer-events: none; user-select: none;&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;[:&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;go&quot; style=&quot;box-sizing: border-box; color: #717171;&quot;&gt;array([10, 12, 14])&lt;/span&gt;
&lt;span class=&quot;gp&quot; style=&quot;box-sizing: border-box; color: navy; font-weight: bold; pointer-events: none; user-select: none;&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;[:&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;:]&lt;/span&gt;
&lt;span class=&quot;go&quot; style=&quot;box-sizing: border-box; color: #717171;&quot;&gt;array([10, 11, 12, 13, 14])&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;다음은 2차원 array관련입니다. 아래 구문은 0번 row만 취합니다.&lt;/p&gt;&lt;div class=&quot;highlight-py notranslate&quot; style=&quot;background-color: #fcfcfc; border: 1px solid rgb(225, 228, 229); box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; margin: 1px 0px 24px; overflow-x: auto;&quot;&gt;&lt;div class=&quot;highlight&quot; style=&quot;background: rgb(248, 248, 248); border: none; box-sizing: border-box; margin: 0px; overflow-x: auto; padding: 0px;&quot;&gt;&lt;pre style=&quot;box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; line-height: 1.4; margin-bottom: 0px; margin-top: 0px; overflow: auto; padding: 12px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;gp&quot; style=&quot;box-sizing: border-box; color: navy; font-weight: bold; pointer-events: none; user-select: none;&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;A&lt;/span&gt; &lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;arange&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;19&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;reshape&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;gp&quot; style=&quot;box-sizing: border-box; color: navy; font-weight: bold; pointer-events: none; user-select: none;&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;A&lt;/span&gt;
&lt;span class=&quot;go&quot; style=&quot;box-sizing: border-box; color: #717171;&quot;&gt;array([[10, 11, 12],&lt;/span&gt;
&lt;span class=&quot;go&quot; style=&quot;box-sizing: border-box; color: #717171;&quot;&gt; [13, 14, 15],&lt;/span&gt;
&lt;span class=&quot;go&quot; style=&quot;box-sizing: border-box; color: #717171;&quot;&gt; [16, 17, 18]])&lt;/span&gt;
&lt;span class=&quot;gp&quot; style=&quot;box-sizing: border-box; color: navy; font-weight: bold; pointer-events: none; user-select: none;&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,:]&lt;/span&gt;
&lt;span class=&quot;go&quot; style=&quot;box-sizing: border-box; color: #717171;&quot;&gt;array([10, 11, 12])&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;아래와 같이 하면 첫번째 column만 취합니다.&lt;/p&gt;&lt;div class=&quot;highlight-py notranslate&quot; style=&quot;background-color: #fcfcfc; border: 1px solid rgb(225, 228, 229); box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; margin: 1px 0px 24px; overflow-x: auto;&quot;&gt;&lt;div class=&quot;highlight&quot; style=&quot;background: rgb(248, 248, 248); border: none; box-sizing: border-box; margin: 0px; overflow-x: auto; padding: 0px;&quot;&gt;&lt;pre style=&quot;box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; line-height: 1.4; margin-bottom: 0px; margin-top: 0px; overflow: auto; padding: 12px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;gp&quot; style=&quot;box-sizing: border-box; color: navy; font-weight: bold; pointer-events: none; user-select: none;&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;[:,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;go&quot; style=&quot;box-sizing: border-box; color: #717171;&quot;&gt;array([10, 13, 16])&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;아래와 같이 할 경우 (3,3) matrix에서 (2,2) matrix를 취합니다.&lt;/p&gt;&lt;div class=&quot;highlight-py notranslate&quot; style=&quot;background-color: #fcfcfc; border: 1px solid rgb(225, 228, 229); box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; margin: 1px 0px 24px; overflow-x: auto;&quot;&gt;&lt;div class=&quot;highlight&quot; style=&quot;background: rgb(248, 248, 248); border: none; box-sizing: border-box; margin: 0px; overflow-x: auto; padding: 0px;&quot;&gt;&lt;pre style=&quot;box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; line-height: 1.4; margin-bottom: 0px; margin-top: 0px; overflow: auto; padding: 12px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;gp&quot; style=&quot;box-sizing: border-box; color: navy; font-weight: bold; pointer-events: none; user-select: none;&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;go&quot; style=&quot;box-sizing: border-box; color: #717171;&quot;&gt;array([[10, 11],&lt;/span&gt;
&lt;span class=&quot;go&quot; style=&quot;box-sizing: border-box; color: #717171;&quot;&gt; [13, 14]])&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;아래는 row를 0행, 2행만 선택적으로 취합니다. column은 0:2로 취하고요&lt;/p&gt;&lt;div class=&quot;highlight-py notranslate&quot; style=&quot;background-color: #fcfcfc; border: 1px solid rgb(225, 228, 229); box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; margin: 1px 0px 24px; overflow-x: auto;&quot;&gt;&lt;div class=&quot;highlight&quot; style=&quot;background: rgb(248, 248, 248); border: none; box-sizing: border-box; margin: 0px; overflow-x: auto; padding: 0px;&quot;&gt;&lt;pre style=&quot;box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, &amp;quot;Liberation Mono&amp;quot;, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 12px; line-height: 1.4; margin-bottom: 0px; margin-top: 0px; overflow: auto; padding: 12px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;gp&quot; style=&quot;box-sizing: border-box; color: navy; font-weight: bold; pointer-events: none; user-select: none;&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/span&gt;&lt;span class=&quot;n&quot; style=&quot;box-sizing: border-box;&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;[[&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot; style=&quot;box-sizing: border-box; color: #666666;&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot; style=&quot;box-sizing: border-box;&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;go&quot; style=&quot;box-sizing: border-box; color: #717171;&quot;&gt;array([[10, 11],&lt;/span&gt;
&lt;span class=&quot;go&quot; style=&quot;box-sizing: border-box; color: #717171;&quot;&gt; [16, 17]])&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;p style=&quot;background-color: #fcfcfc; box-sizing: border-box; color: #404040; font-family: Lato, proxima-nova, &amp;quot;Helvetica Neue&amp;quot;, Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 0px 0px 24px;&quot;&gt;위 방법들은 다 이해하기도 어렵고 이런 류의 식들은 사실 머리로 이해하기보다는, 자주 쓰면서 손에 익는 류라고 보면 될 거 같습니다. 이 NumPy가 비슷하면서도 기존 파이썬과의 차이점들이 존재하니 이런 부분들을 이해하고 차이를 구분해서 쓰는게 중요해 보이네요&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://pyengine.blogspot.com/feeds/6353266935373410554/comments/default' title='댓글'/><link rel='replies' type='text/html' href='http://pyengine.blogspot.com/2022/10/numpy-slicing.html#comment-form' title='0개의 덧글'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4881868893095669586/posts/default/6353266935373410554'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4881868893095669586/posts/default/6353266935373410554'/><link rel='alternate' type='text/html' href='http://pyengine.blogspot.com/2022/10/numpy-slicing.html' title='Numpy Slicing'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>