Skip to content

Commit e46c514

Browse files
authored
Merge pull request #4 from reina314/dev
Dev
2 parents 6ff5996 + dc67943 commit e46c514

6 files changed

Lines changed: 426 additions & 11 deletions

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<template>
2+
<div class="py-3">
3+
<div class="container bg-black-800 border border-green-600 rounded my-3 px-3 py-3">
4+
<p class="-mt-2 text-sm">bash</p>
5+
<div id="text" class="relative px-3 rounded bg-white text-black">
6+
user@Ri-one ~ $ <slot></slot>
7+
<button data-copy-to-clipboard-target="npm-install-copy-button" data-tooltip-target="tooltip-copy-npm-install-copy-button" class="absolute end-2 top-1/2 -translate-y-1/2 text-gray-500 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-800 rounded-lg p-2 inline-flex items-center justify-center">
8+
<span id="default-icon">
9+
<svg class="w-3.5 h-3.5" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 18 20">
10+
<path d="M16 1h-3.278A1.992 1.992 0 0 0 11 0H7a1.993 1.993 0 0 0-1.722 1H2a2 2 0 0 0-2 2v15a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V3a2 2 0 0 0-2-2Zm-3 14H5a1 1 0 0 1 0-2h8a1 1 0 0 1 0 2Zm0-4H5a1 1 0 0 1 0-2h8a1 1 0 1 1 0 2Zm0-5H5a1 1 0 0 1 0-2h2V2h4v2h2a1 1 0 1 1 0 2Z"/>
11+
</svg>
12+
</span>
13+
<span id="success-icon" class="hidden inline-flex items-center">
14+
<svg class="w-3.5 h-3.5 text-blue-700 dark:text-blue-500" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 16 12">
15+
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M1 5.917 5.724 10.5 15 1.5"/>
16+
</svg>
17+
</span>
18+
</button>
19+
<div id="tooltip-copy-npm-install-copy-button" role="tooltip" class="absolute z-10 invisible inline-block px-3 py-2 text-sm font-medium text-white transition-opacity duration-300 bg-gray-900 rounded-lg shadow-sm opacity-0 tooltip dark:bg-gray-700">
20+
<span id="default-tooltip-message">Copy to clipboard</span>
21+
<span id="success-tooltip-message" class="hidden">Copied!</span>
22+
<div class="tooltip-arrow" data-popper-arrow></div>
23+
</div>
24+
</div>
25+
</div>
26+
</div>
27+
</template>
28+
29+
<style scoped>
30+
#text {
31+
font-family: monospace;
32+
font-size: large;
33+
}
34+
</style>

app/lecture/src/components/PyScript.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<div class="container bg-black-800 border border-green-600 rounded my-3 px-3 py-3">
3-
<p class="text-md">Python3.11</p>
3+
<p class="-mt-1 text-sm">Python3.11</p>
44
<div class="px-3 rounded bg-white text-black">
55
<py-repl>
66
<slot></slot>

app/lecture/src/views/Lecture3.vue

Lines changed: 99 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
</script>
3232

3333
<template>
34-
<Title>第3講 Python: 配列辞書</Title>
34+
<Title>第3講 Python: 配列辞書</Title>
3535

3636
<div class="container w-3/6 mx-auto mb-10 text-start">
3737
<Header>1.配列</Header>
@@ -51,7 +51,7 @@
5151

5252
上の例では、1行目でstr型のデータを格納したlistを定義している。
5353
listに格納されたデータは、food[0]のように、listの変数名の後ろにインデックス(<span class="text-yellow-400">index</span>)を指定することでアクセスできる。
54-
ここで、indexが0オリジン(<span class="text-yellow-400">zero-based</span>)であることには十分注意してほしい
54+
ここで、indexが0オリジン(<span class="text-yellow-400">zero-based</span>)であることに十分注意してほしい
5555
</Paragraph>
5656

5757
<Paragraph>
@@ -69,7 +69,7 @@
6969
</Paragraph>
7070

7171
<Paragraph>
72-
補足: Pythonにおけるlistは、一般的なCやJavaの配列とは異なり、動的配列(<span class="text-yellow-400">dynamic array</span>)である。これは、list内のデータが増減するたびに、自動的にメモリ領域が再割り当てされるということである。従って、事前に定まったメモリ領域を確保し、管理するという手間は生じない。<br>
72+
補足: Pythonにおけるlistは、一般的なCやJavaの配列とは異なり、動的配列(<span class="text-yellow-400">dynamic array</span>)である。これは、list内のデータが増減するたびに、自動的にメモリ領域が再割り当てされるということである。したがって、事前に定まったメモリ領域を確保し、管理するという手間は生じない。<br>
7373
これは、C++におけるstd::vectorやJavaにおけるjava.util.ArrayListなどのライブラリが実装するものと同様の機能である。
7474
</Paragraph>
7575

@@ -91,7 +91,7 @@
9191
</Paragraph>
9292

9393
<Paragraph>
94-
従って、配列の全ての要素を書き換えるためには次のようにすること。
94+
したがって、配列の全ての要素を書き換えるためには次のようにすること。
9595

9696
<PyScript>
9797
food = ['Apple', 'Banana', 'Cherry', 'Durian', 'Eggplant']
@@ -248,7 +248,7 @@
248248

249249
<Header>2.辞書</Header>
250250
<Paragraph>
251-
配列について理解できれば、辞書(<span class="text-yellow-400">dictionary</span>)を理解するのはそれほど難しいことではない。なぜなら、辞書は配列のindexの代わりに任意のキー(<span class="text-yellow-400">key</span>)を用いるに過ぎないからである
251+
配列について理解できれば、辞書(<span class="text-yellow-400">dictionary</span>)を理解するのはそれほど難しいことではない。なぜなら辞書は、配列のindexにスカラー値以外のデータ型も用いられるに過ぎないからである。また、辞書のindexをキー(<span class="text-yellow-400">key</span>)と呼ぶ
252252

253253
<SubHeader>辞書の基本</SubHeader>
254254
<Paragraph>
@@ -321,9 +321,36 @@
321321
</PyScript>
322322
</Paragraph>
323323

324+
<Paragraph>
325+
次に、要素を削除する方法を示す。
326+
327+
<PyScript>
328+
desktop = {"os": "Windows 11", "cpu": "Xeon", "gpu": "RTX 4090"}
329+
330+
desktop.pop("cpu")
331+
print(desktop)
332+
</PyScript>
333+
334+
<PyScript>
335+
desktop = {"os": "Windows 11", "cpu": "Xeon", "gpu": "RTX 4090"}
336+
337+
del desktop["cpu"]
338+
print(desktop)
339+
</PyScript>
340+
341+
<PyScript>
342+
desktop = {"os": "Windows 11", "cpu": "Xeon", "gpu": "RTX 4090"}
343+
344+
desktop = {k: v for k, v in desktop.items() if k != "cpu"}
345+
print(desktop)
346+
</PyScript>
347+
348+
このように、配列とほぼ同様にして値を操作することができる。
349+
</Paragraph>
350+
324351
<SubHeader>配列と辞書</SubHeader>
325352
<Paragraph>
326-
配列と辞書は、互いに入れ子になることが可能である
353+
配列と辞書は、互いに入れ子にすることが可能である
327354
具体例を見てみるとしよう。
328355

329356
<PyScript>
@@ -349,7 +376,72 @@
349376

350377
<Header>3.練習問題</header>
351378
<Paragraph>
352-
近日公開! 乞うご期待
379+
作問者からのお願い: numpyを使わないで下さい。全問、一瞬で易化します。最後の問題のみ、あらかじめmathライブラリをインポートしておきました。
380+
</Paragraph>
381+
<Paragraph>
382+
<SubHeader class="mb-3">[<span class="text-green-600 font-bold">Easy</span>] 次のデータを正規化せよ。</SubHeader>
383+
<Hint level="easy">グレイスケール(8bit)ですね。</Hint>
384+
385+
<PyScript>
386+
data = [
387+
[133, 254, 0, 233, 45],
388+
[230, 43, 198, 172, 85],
389+
[ 75, 189, 34, 210, 222],
390+
[ 43, 240, 65, 184, 202],
391+
[139, 14, 78, 255, 164]
392+
]
393+
# 続きを書いてね
394+
395+
print(normalized_data)
396+
</PyScript>
397+
</Paragraph>
398+
399+
<Paragraph>
400+
<SubHeader class="mb-3">[<span class="text-yellow-400 font-bold">Medium</span>] 次のデータを昇順(ascending order)に並べ替えよ。ただし、バブルソートを使うこと。</SubHeader>
401+
<Hint level="med1">各データが泡のように浮かび上がってきます。</Hint>
402+
403+
<PyScript>
404+
data = [5, 9, 3, 6, 2, 1, 3, 7, 8, 0]
405+
# 続きを書いてね
406+
407+
print(sorted_data)
408+
</PyScript>
409+
</Paragraph>
410+
411+
<Paragraph>
412+
<SubHeader class="mb-3">[<span class="text-yellow-400 font-bold">Medium</span>] 行列Aと行列Bの積を求めよ。</SubHeader>
413+
<Hint level="med2">定義通りに計算しよう。(※手計算しないでね)</Hint>
414+
415+
<PyScript>
416+
A = [
417+
[1, 2, 3],
418+
[4, 5, 6],
419+
[7, 8, 9]
420+
]
421+
B = [
422+
[-1, 0, 1],
423+
[ 0, 1, -1],
424+
[ 1, -1, -1]
425+
]
426+
# 続きを書いてね
427+
428+
print(C)
429+
</PyScript>
430+
</Paragraph>
431+
432+
<Paragraph>
433+
<SubHeader class="mb-3">[<span class="text-yellow-400 font-bold">Medium</span>] データAとデータBの相関係数を求めよ。</SubHeader>
434+
<Hint level="med3">平方根は、<span class="text-yellow-400">math.sqrt()</span>関数で計算できる。</Hint>
435+
436+
<PyScript>
437+
import math
438+
439+
data_A = [ 0, 3, 5, 9, -2, 1, 2, -4, 7, 8]
440+
data_B = [ 3, 12, 6, 5, 4, -2, 3, -1, 9, 7]
441+
# 続きを書いてね
442+
443+
print(cor_AB)
444+
</PyScript>
353445
</Paragraph>
354446

355447
<ProgressFooter :progress="completion" class="mt-16" />

0 commit comments

Comments
 (0)