Skip to content

Commit b26f7cf

Browse files
committed
Colaboratory를 통해 생성됨
1 parent 85f66d6 commit b26f7cf

File tree

1 file changed

+320
-0
lines changed

1 file changed

+320
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,320 @@
1+
{
2+
"nbformat": 4,
3+
"nbformat_minor": 0,
4+
"metadata": {
5+
"colab": {
6+
"name": "Numpy의 기본 사용법",
7+
"version": "0.3.2",
8+
"provenance": [],
9+
"include_colab_link": true
10+
},
11+
"kernelspec": {
12+
"name": "python3",
13+
"display_name": "Python 3"
14+
}
15+
},
16+
"cells": [
17+
{
18+
"cell_type": "markdown",
19+
"metadata": {
20+
"id": "view-in-github",
21+
"colab_type": "text"
22+
},
23+
"source": [
24+
"<a href=\"https://colab.research.google.com/github/ndb796/Python-Data-Analysis-and-Image-Processing-Tutorial/blob/master/03.%20Numpy%EC%9D%98%20%EA%B8%B0%EB%B3%B8%20%EC%82%AC%EC%9A%A9%EB%B2%95/Numpy%EC%9D%98%20%EA%B8%B0%EB%B3%B8%20%EC%82%AC%EC%9A%A9%EB%B2%95.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
25+
]
26+
},
27+
{
28+
"cell_type": "markdown",
29+
"metadata": {
30+
"id": "XK5zqqXSD5Vd",
31+
"colab_type": "text"
32+
},
33+
"source": [
34+
"## Numpy의 기본 사용법\n",
35+
"[강의 노트](https://github.com/ndb796/Python-Data-Analysis-and-Image-Processing-Tutorial/blob/master/04.%20Numpy%EC%9D%98%20%EC%97%B0%EC%82%B0%EA%B3%BC%20%ED%95%A8%EC%88%98/Python%20%EB%8D%B0%EC%9D%B4%ED%84%B0%20%EB%B6%84%EC%84%9D%EA%B3%BC%20%EC%9D%B4%EB%AF%B8%EC%A7%80%20%EC%B2%98%EB%A6%AC%20-%20Numpy%EC%9D%98%20%EC%97%B0%EC%82%B0%EA%B3%BC%20%ED%95%A8%EC%88%98.pdf)"
36+
]
37+
},
38+
{
39+
"cell_type": "markdown",
40+
"metadata": {
41+
"id": "hqGi-UyhFFBM",
42+
"colab_type": "text"
43+
},
44+
"source": [
45+
"Python의 Numpy 라이브러리는 List와 **상호 변환이 가능**합니다."
46+
]
47+
},
48+
{
49+
"cell_type": "code",
50+
"metadata": {
51+
"id": "G5AmgwzoENVh",
52+
"colab_type": "code",
53+
"colab": {
54+
"base_uri": "https://localhost:8080/",
55+
"height": 70
56+
},
57+
"outputId": "3de972b6-6dd8-4bf0-d559-5d800fdee864"
58+
},
59+
"source": [
60+
"import numpy as np\n",
61+
"\n",
62+
"array = np.array([1, 2, 3])\n",
63+
"print(array.size) # 배열의 크기\n",
64+
"print(array.dtype) # 배열 원소의 타입\n",
65+
"print(array[2]) # 인덱스 2의 원소"
66+
],
67+
"execution_count": 18,
68+
"outputs": [
69+
{
70+
"output_type": "stream",
71+
"text": [
72+
"3\n",
73+
"int64\n",
74+
"3\n"
75+
],
76+
"name": "stdout"
77+
}
78+
]
79+
},
80+
{
81+
"cell_type": "markdown",
82+
"metadata": {
83+
"id": "bzE_pyEHEUXU",
84+
"colab_type": "text"
85+
},
86+
"source": [
87+
"Python의 Numpy 라이브러리는 **다양한 형태의 배열**을 초기화 할 수 있습니다."
88+
]
89+
},
90+
{
91+
"cell_type": "code",
92+
"metadata": {
93+
"id": "MO-eC8rzEPKK",
94+
"colab_type": "code",
95+
"colab": {
96+
"base_uri": "https://localhost:8080/",
97+
"height": 263
98+
},
99+
"outputId": "f3581290-5dfc-4995-b850-78579cfce320"
100+
},
101+
"source": [
102+
"import numpy as np\n",
103+
"\n",
104+
"# 0부터 3까지의 배열 만들기\n",
105+
"array1 = np.arange(4)\n",
106+
"print(array1)\n",
107+
"\n",
108+
"# 0으로 초기화\n",
109+
"array2 = np.zeros((4, 4), dtype=float)\n",
110+
"print(array2)\n",
111+
"\n",
112+
"# 1로 초기화\n",
113+
"array3 = np.ones((3, 3), dtype=str)\n",
114+
"print(array3)\n",
115+
"\n",
116+
"# 0부터 9까지 랜덤하게 초기화 된 배열 만들기\n",
117+
"array4 = np.random.randint(0, 10, (3, 3))\n",
118+
"print(array4)\n",
119+
"\n",
120+
"# 평균이 0이고 표준편차가 1인 표준 정규를 띄는 배열\n",
121+
"array5 = np.random.normal(0, 1, (3, 3))\n",
122+
"print(array5)"
123+
],
124+
"execution_count": 19,
125+
"outputs": [
126+
{
127+
"output_type": "stream",
128+
"text": [
129+
"[0 1 2 3]\n",
130+
"[[0. 0. 0. 0.]\n",
131+
" [0. 0. 0. 0.]\n",
132+
" [0. 0. 0. 0.]\n",
133+
" [0. 0. 0. 0.]]\n",
134+
"[['1' '1' '1']\n",
135+
" ['1' '1' '1']\n",
136+
" ['1' '1' '1']]\n",
137+
"[[9 6 6]\n",
138+
" [6 2 1]\n",
139+
" [1 6 3]]\n",
140+
"[[-0.85995876 -2.27512351 -1.15556506]\n",
141+
" [-0.5298595 0.18397865 0.03568352]\n",
142+
" [ 0.00741686 -0.54831076 -1.38529353]]\n"
143+
],
144+
"name": "stdout"
145+
}
146+
]
147+
},
148+
{
149+
"cell_type": "markdown",
150+
"metadata": {
151+
"id": "BjNuQEp7FWJ1",
152+
"colab_type": "text"
153+
},
154+
"source": [
155+
"Numpy는 다양한 형태로 **합치기가 가능** 있습니다."
156+
]
157+
},
158+
{
159+
"cell_type": "code",
160+
"metadata": {
161+
"id": "Yracqt2SEcDw",
162+
"colab_type": "code",
163+
"colab": {
164+
"base_uri": "https://localhost:8080/",
165+
"height": 52
166+
},
167+
"outputId": "1c4c399b-e848-4c82-aa9f-f2949b09b714"
168+
},
169+
"source": [
170+
"import numpy as np\n",
171+
"\n",
172+
"array1 = np.array([1, 2, 3]) \n",
173+
"array2 = np.array([4, 5, 6])\n",
174+
"array3 = np.concatenate([array1, array2])\n",
175+
"\n",
176+
"print(array3.shape)\n",
177+
"print(array3)"
178+
],
179+
"execution_count": 20,
180+
"outputs": [
181+
{
182+
"output_type": "stream",
183+
"text": [
184+
"(6,)\n",
185+
"[1 2 3 4 5 6]\n"
186+
],
187+
"name": "stdout"
188+
}
189+
]
190+
},
191+
{
192+
"cell_type": "markdown",
193+
"metadata": {
194+
"id": "4pN-EeEDGHb1",
195+
"colab_type": "text"
196+
},
197+
"source": [
198+
"Numpy를 위 아래로 합칠 수 있습니다."
199+
]
200+
},
201+
{
202+
"cell_type": "code",
203+
"metadata": {
204+
"id": "u5z29qIHGHiw",
205+
"colab_type": "code",
206+
"colab": {
207+
"base_uri": "https://localhost:8080/",
208+
"height": 87
209+
},
210+
"outputId": "5df72b78-0439-45eb-ff74-a3b8bd233ba4"
211+
},
212+
"source": [
213+
"import numpy as np\n",
214+
"\n",
215+
"array1 = np.arange(4).reshape(1, 4)\n",
216+
"array2 = np.arange(8).reshape(2, 4)\n",
217+
"array3 = np.concatenate([array1, array2], axis=0)\n",
218+
"\n",
219+
"print(array3.shape)\n",
220+
"print(array3)"
221+
],
222+
"execution_count": 21,
223+
"outputs": [
224+
{
225+
"output_type": "stream",
226+
"text": [
227+
"(3, 4)\n",
228+
"[[0 1 2 3]\n",
229+
" [0 1 2 3]\n",
230+
" [4 5 6 7]]\n"
231+
],
232+
"name": "stdout"
233+
}
234+
]
235+
},
236+
{
237+
"cell_type": "markdown",
238+
"metadata": {
239+
"id": "0kFRNyINFzRd",
240+
"colab_type": "text"
241+
},
242+
"source": [
243+
"Numpy의 **형태를 변경**할 수 있습니다."
244+
]
245+
},
246+
{
247+
"cell_type": "code",
248+
"metadata": {
249+
"id": "I-RVSif4Feht",
250+
"colab_type": "code",
251+
"colab": {
252+
"base_uri": "https://localhost:8080/",
253+
"height": 34
254+
},
255+
"outputId": "a1fd982a-0e01-4bdb-9603-db80b58ce367"
256+
},
257+
"source": [
258+
"import numpy as np\n",
259+
"\n",
260+
"array1 = np.array([1, 2, 3, 4])\n",
261+
"array2 = array1.reshape((2, 2))\n",
262+
"print(array2.shape)"
263+
],
264+
"execution_count": 22,
265+
"outputs": [
266+
{
267+
"output_type": "stream",
268+
"text": [
269+
"(2, 2)\n"
270+
],
271+
"name": "stdout"
272+
}
273+
]
274+
},
275+
{
276+
"cell_type": "markdown",
277+
"metadata": {
278+
"id": "ZIy_DX6bGDpd",
279+
"colab_type": "text"
280+
},
281+
"source": [
282+
"Numpy의 **형태를 나누기** 할 수 있습니다."
283+
]
284+
},
285+
{
286+
"cell_type": "code",
287+
"metadata": {
288+
"id": "yQGYnY2pF875",
289+
"colab_type": "code",
290+
"colab": {
291+
"base_uri": "https://localhost:8080/",
292+
"height": 70
293+
},
294+
"outputId": "1c84ae7d-f899-4066-8287-f5ad35e1abc3"
295+
},
296+
"source": [
297+
"import numpy as np\n",
298+
"\n",
299+
"array = np.arange(8).reshape(2, 4)\n",
300+
"left, right = np.split(array, [2], axis=1)\n",
301+
"\n",
302+
"print(left.shape)\n",
303+
"print(right.shape)\n",
304+
"print(right[1][1])"
305+
],
306+
"execution_count": 23,
307+
"outputs": [
308+
{
309+
"output_type": "stream",
310+
"text": [
311+
"(2, 2)\n",
312+
"(2, 2)\n",
313+
"7\n"
314+
],
315+
"name": "stdout"
316+
}
317+
]
318+
}
319+
]
320+
}

0 commit comments

Comments
 (0)