From 865665a43d05abaf04620fc5cd526b6f4a930960 Mon Sep 17 00:00:00 2001 From: chvmvd Date: Sun, 6 Nov 2022 16:09:23 +0900 Subject: [PATCH 1/7] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=B1=A5=E6=AD=B4?= =?UTF-8?q?=E3=81=AE=E5=90=91=E3=81=8D=E3=82=92=E9=80=86=E3=81=AB=E3=81=97?= =?UTF-8?q?=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/index.mdx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/index.mdx b/docs/index.mdx index 0f4739ced..a8ce9fc47 100644 --- a/docs/index.mdx +++ b/docs/index.mdx @@ -24,12 +24,12 @@ Python やアルゴリズムについて簡単にまとめていこうかなと ## 更新履歴 -10/10 第一周の分を執筆 [ここから](/docs/python/01google-colaboratory/) +10/30 第三週の分を執筆 [ここから](/docs/python/07for/) -10/10 練習問題を追加 +10/23 第二週の分を執筆 [ここから](/docs/python/05function/) 10/16 練習問題をさらに追加 -10/23 第二週の分を執筆 [ここから](/docs/python/05function/) +10/10 練習問題を追加 -10/30 第三週の分を執筆 [ここから](/docs/python/07for/) +10/10 第一周の分を執筆 [ここから](/docs/python/01google-colaboratory/) From b3ab704f9ce12260406c4e06a3dec2802feef1d3 Mon Sep 17 00:00:00 2001 From: chvmvd Date: Sun, 6 Nov 2022 16:14:07 +0900 Subject: [PATCH 2/7] =?UTF-8?q?LaTeX=E3=81=AEsum=E3=82=92limits=E3=81=AB?= =?UTF-8?q?=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/python/08array/index.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/python/08array/index.mdx b/docs/python/08array/index.mdx index 9d5513ae7..054ec1340 100644 --- a/docs/python/08array/index.mdx +++ b/docs/python/08array/index.mdx @@ -88,7 +88,7 @@ len(配列名) $n$ 個の観測データを $x_1,x_2,\cdots,x_n$ 、平均を $\bar{x}$ とすると、分散 $s^2$ は次のように与えられるとします。 $$ -s^2=\frac{\sum_{i=1}^n(x_i-\bar{x})^2}{n} +s^2=\frac{\sum\limits_{i=1}^n(x_i-\bar{x})^2}{n} $$ 練習問題 1 と同じように具体的な値を入れて確かめてみましょう。 From 885fb5b7d07d8b10956c84d836d766f995ffc867 Mon Sep 17 00:00:00 2001 From: chvmvd Date: Sun, 6 Nov 2022 16:17:35 +0900 Subject: [PATCH 3/7] =?UTF-8?q?f-string=E3=81=AE=E8=A9=B1=E3=82=92note?= =?UTF-8?q?=E3=81=AB=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/python/05function/index.mdx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/python/05function/index.mdx b/docs/python/05function/index.mdx index 721b74b18..5940265c4 100644 --- a/docs/python/05function/index.mdx +++ b/docs/python/05function/index.mdx @@ -87,7 +87,9 @@ $G=6.7\times 10^{-11}$、$r=2$、$M=60$、$m=20$ とします。 +:::note `f-string` を使わないと次のようになります。 +::: From 48a0fc02aebb298ce495bd99b188747cc35a08ad Mon Sep 17 00:00:00 2001 From: chvmvd Date: Sun, 6 Nov 2022 16:33:27 +0900 Subject: [PATCH 4/7] =?UTF-8?q?=E5=88=86=E6=95=A3=E3=82=92=E3=83=A9?= =?UTF-8?q?=E3=82=A4=E3=83=96=E3=83=A9=E3=83=AA=E3=82=92=E4=BD=BF=E3=81=A3?= =?UTF-8?q?=E3=81=9F=E6=96=B9=E6=B3=95=E3=82=82=E5=85=A5=E3=82=8C=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../08array/_samples/variance_numpy.ipynb | 27 +++++++++++++++++++ .../_samples/variance_statistics.ipynb | 27 +++++++++++++++++++ docs/python/08array/index.mdx | 7 +++++ 3 files changed, 61 insertions(+) create mode 100644 docs/python/08array/_samples/variance_numpy.ipynb create mode 100644 docs/python/08array/_samples/variance_statistics.ipynb diff --git a/docs/python/08array/_samples/variance_numpy.ipynb b/docs/python/08array/_samples/variance_numpy.ipynb new file mode 100644 index 000000000..3ce5b5ef8 --- /dev/null +++ b/docs/python/08array/_samples/variance_numpy.ipynb @@ -0,0 +1,27 @@ +{ + "nbformat": 4, + "nbformat_minor": 2, + "metadata": {}, + "cells": [ + { + "metadata": {}, + "source": [ + "import numpy\n", + "\n", + "scores = [26, 78, 83, 20, 10, 11, 22, 16, 41, 95]\n", + "print(numpy.var(scores))" + ], + "cell_type": "code", + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "955.5600000000001\n" + ] + } + ], + "execution_count": null + } + ] +} diff --git a/docs/python/08array/_samples/variance_statistics.ipynb b/docs/python/08array/_samples/variance_statistics.ipynb new file mode 100644 index 000000000..1cda7d666 --- /dev/null +++ b/docs/python/08array/_samples/variance_statistics.ipynb @@ -0,0 +1,27 @@ +{ + "nbformat": 4, + "nbformat_minor": 2, + "metadata": {}, + "cells": [ + { + "metadata": {}, + "source": [ + "import statistics\n", + "\n", + "scores = [26, 78, 83, 20, 10, 11, 22, 16, 41, 95]\n", + "print(statistics.pvariance(scores))" + ], + "cell_type": "code", + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "955.56\n" + ] + } + ], + "execution_count": null + } + ] +} diff --git a/docs/python/08array/index.mdx b/docs/python/08array/index.mdx index 054ec1340..064f26d5e 100644 --- a/docs/python/08array/index.mdx +++ b/docs/python/08array/index.mdx @@ -99,4 +99,11 @@ $$ 次のようにしても計算できますが( `variance` 関数の中が少し変わっています。)、for 文の中が実行される度に `average` 関数が実行されて計算量が多くなってしまうので、上のようにした方が良いでしょう。 + +実は、分散を計算するライブラリがあります。[statistics ライブラリの pvariance 関数](https://docs.python.org/ja/3/library/statistics.html#statistics.pvariance)を使う方法や[NumPy ライブラリの var 関数](https://numpy.org/doc/stable/reference/generated/numpy.var.html)があります。 + + + + + From ed81ba2d2f223a06538b203cca76127f68f570a9 Mon Sep 17 00:00:00 2001 From: chvmvd Date: Sun, 6 Nov 2022 16:49:00 +0900 Subject: [PATCH 5/7] =?UTF-8?q?=E5=B9=B3=E5=9D=87=E3=82=92=E3=83=A9?= =?UTF-8?q?=E3=82=A4=E3=83=96=E3=83=A9=E3=83=AA=E3=82=92=E4=BD=BF=E3=81=A3?= =?UTF-8?q?=E3=81=9F=E6=96=B9=E6=B3=95=E3=82=82=E7=B4=B9=E4=BB=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../08array/_samples/average_numpy.ipynb | 30 +++++++++++++++++++ .../08array/_samples/average_statistics.ipynb | 30 +++++++++++++++++++ docs/python/08array/index.mdx | 8 ++++- 3 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 docs/python/08array/_samples/average_numpy.ipynb create mode 100644 docs/python/08array/_samples/average_statistics.ipynb diff --git a/docs/python/08array/_samples/average_numpy.ipynb b/docs/python/08array/_samples/average_numpy.ipynb new file mode 100644 index 000000000..3186bed88 --- /dev/null +++ b/docs/python/08array/_samples/average_numpy.ipynb @@ -0,0 +1,30 @@ +{ + "nbformat": 4, + "nbformat_minor": 2, + "metadata": {}, + "cells": [ + { + "metadata": {}, + "source": [ + "import numpy\n", + "\n", + "scores = [26, 78, 83, 20, 10, 11, 22, 16, 41, 95]\n", + "numpy.mean(scores)" + ], + "cell_type": "code", + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "40.2" + ] + }, + "metadata": {}, + "execution_count": 1 + } + ], + "execution_count": null + } + ] +} diff --git a/docs/python/08array/_samples/average_statistics.ipynb b/docs/python/08array/_samples/average_statistics.ipynb new file mode 100644 index 000000000..c7077fdf4 --- /dev/null +++ b/docs/python/08array/_samples/average_statistics.ipynb @@ -0,0 +1,30 @@ +{ + "nbformat": 4, + "nbformat_minor": 2, + "metadata": {}, + "cells": [ + { + "metadata": {}, + "source": [ + "import statistics\n", + "\n", + "scores = [26, 78, 83, 20, 10, 11, 22, 16, 41, 95]\n", + "statistics.mean(scores)" + ], + "cell_type": "code", + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "40.2" + ] + }, + "metadata": {}, + "execution_count": 1 + } + ], + "execution_count": null + } + ] +} diff --git a/docs/python/08array/index.mdx b/docs/python/08array/index.mdx index 064f26d5e..9fb447984 100644 --- a/docs/python/08array/index.mdx +++ b/docs/python/08array/index.mdx @@ -78,7 +78,13 @@ len(配列名) 実際に、点数をそれぞれ 26 点、78 点、83 点、20 点、10 点、11 点、22 点、16 点、41 点、95 点として計算してみましょう。 - + + +実は、平均点を求めるライブラリもあります。[statistics ライブラリの mean 関数](https://docs.python.org/ja/3/library/statistics.html#statistics.mean)や[numpy ライブラリの mean 関数](https://numpy.org/doc/stable/reference/generated/numpy.mean.html)があります。 + + + + ### 練習問題 2 From c4a53ff7f96485bbfbbd13806a1761d569e8fa04 Mon Sep 17 00:00:00 2001 From: chvmvd Date: Sun, 6 Nov 2022 17:10:31 +0900 Subject: [PATCH 6/7] =?UTF-8?q?range=E9=96=A2=E6=95=B0=E3=81=AB=E3=81=A4?= =?UTF-8?q?=E3=81=84=E3=81=A6=E5=9F=B7=E7=AD=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/index.mdx | 2 ++ docs/python/07for/_samples/upto_sum.ipynb | 27 +++++++++++++++++++++++ docs/python/07for/index.mdx | 8 +++++-- docs/python/08array/_samples/range.ipynb | 26 ++++++++++++++++++++++ docs/python/08array/_samples/sum.ipynb | 27 +++++++++++++++++++++++ docs/python/08array/_samples/sum2.ipynb | 27 +++++++++++++++++++++++ docs/python/08array/index.mdx | 13 +++++++++++ 7 files changed, 128 insertions(+), 2 deletions(-) create mode 100644 docs/python/07for/_samples/upto_sum.ipynb create mode 100644 docs/python/08array/_samples/range.ipynb create mode 100644 docs/python/08array/_samples/sum.ipynb create mode 100644 docs/python/08array/_samples/sum2.ipynb diff --git a/docs/index.mdx b/docs/index.mdx index a8ce9fc47..d6f778852 100644 --- a/docs/index.mdx +++ b/docs/index.mdx @@ -24,6 +24,8 @@ Python やアルゴリズムについて簡単にまとめていこうかなと ## 更新履歴 +11/6 range 関数についてを補足 [この下](http://localhost:3000/docs/python/08array/#%E5%95%8F%E9%A1%8C-1) + 10/30 第三週の分を執筆 [ここから](/docs/python/07for/) 10/23 第二週の分を執筆 [ここから](/docs/python/05function/) diff --git a/docs/python/07for/_samples/upto_sum.ipynb b/docs/python/07for/_samples/upto_sum.ipynb new file mode 100644 index 000000000..a2c281e31 --- /dev/null +++ b/docs/python/07for/_samples/upto_sum.ipynb @@ -0,0 +1,27 @@ +{ + "nbformat": 4, + "nbformat_minor": 2, + "metadata": {}, + "cells": [ + { + "metadata": {}, + "source": [ + "sum(range(1, 11))" + ], + "cell_type": "code", + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "55" + ] + }, + "metadata": {}, + "execution_count": 1 + } + ], + "execution_count": null + } + ] +} diff --git a/docs/python/07for/index.mdx b/docs/python/07for/index.mdx index 465e666fd..bd75b4224 100644 --- a/docs/python/07for/index.mdx +++ b/docs/python/07for/index.mdx @@ -92,10 +92,14 @@ while(条件): ### 練習問題 1 -1 から n までの和を求める関数を作って、実際に 1 から 10 までの和を求めてみましょう。 +$1$ から $n$ までの和を求める関数を作って、実際に 1 から 10 までの和を求めてみましょう。 - + + +実は、このプログラムは次のようにしてもっと簡単に書くことができます。しかし、次項の配列の内容がわかっていないと理解できないため、次項で詳しく紹介します。 + + ### 練習問題 2 diff --git a/docs/python/08array/_samples/range.ipynb b/docs/python/08array/_samples/range.ipynb new file mode 100644 index 000000000..ec16de854 --- /dev/null +++ b/docs/python/08array/_samples/range.ipynb @@ -0,0 +1,26 @@ +{ + "nbformat": 4, + "nbformat_minor": 2, + "metadata": {}, + "cells": [ + { + "metadata": {}, + "source": [ + "print(range(1, 11))\n", + "print(list(range(1, 11)))" + ], + "cell_type": "code", + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "range(1, 11)\n", + "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n" + ] + } + ], + "execution_count": null + } + ] +} diff --git a/docs/python/08array/_samples/sum.ipynb b/docs/python/08array/_samples/sum.ipynb new file mode 100644 index 000000000..0d9053bef --- /dev/null +++ b/docs/python/08array/_samples/sum.ipynb @@ -0,0 +1,27 @@ +{ + "nbformat": 4, + "nbformat_minor": 2, + "metadata": {}, + "cells": [ + { + "metadata": {}, + "source": [ + "sum([1, 2, 3])" + ], + "cell_type": "code", + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "6" + ] + }, + "metadata": {}, + "execution_count": 2 + } + ], + "execution_count": null + } + ] +} diff --git a/docs/python/08array/_samples/sum2.ipynb b/docs/python/08array/_samples/sum2.ipynb new file mode 100644 index 000000000..a9c0953ee --- /dev/null +++ b/docs/python/08array/_samples/sum2.ipynb @@ -0,0 +1,27 @@ +{ + "nbformat": 4, + "nbformat_minor": 2, + "metadata": {}, + "cells": [ + { + "metadata": {}, + "source": [ + "sum([2, 5, 7])" + ], + "cell_type": "code", + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "14" + ] + }, + "metadata": {}, + "execution_count": 1 + } + ], + "execution_count": null + } + ] +} diff --git a/docs/python/08array/index.mdx b/docs/python/08array/index.mdx index 9fb447984..45f905f77 100644 --- a/docs/python/08array/index.mdx +++ b/docs/python/08array/index.mdx @@ -72,6 +72,19 @@ len(配列名) +:::info +実は for 文を書くときに出てきた range は、配列のようなものを作る関数です。ここで、配列のようなものと言ったのは厳密には配列ではないからですが、ひとまず配列と考えて問題ないでしょう。そのため、例えば `range(1, 11)` は `[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]` を生成します。下のプログラムでは、range 関数の返り値を配列にしています。 + + + +前項の練習問題の解答で `sum(range(1, 11))` のような別解がありましたが、sum 関数は与えられた配列の和を求める関数なので、これは range 関数で 1 から 10 までの配列を作り、それの和を sum 関数で求めていたということです。 + + + + + +::: + ### 練習問題 1 生徒の英語の点数が書かれた配列を受け取って、その平均点を返す関数を作ってみましょう。 From 692c86e98461818efee50f4ce884f22a204ae511 Mon Sep 17 00:00:00 2001 From: chvmvd Date: Sun, 6 Nov 2022 17:15:30 +0900 Subject: [PATCH 7/7] =?UTF-8?q?=E3=83=90=E3=83=83=E3=82=AF=E3=82=B9?= =?UTF-8?q?=E3=83=A9=E3=83=83=E3=82=B7=E3=83=A5=E3=81=AEmac=E3=81=A7?= =?UTF-8?q?=E3=81=AE=E6=89=93=E3=81=A1=E6=96=B9=E3=82=92=E8=BF=BD=E8=A8=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/extras/5tex/index.mdx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/extras/5tex/index.mdx b/docs/extras/5tex/index.mdx index 5e0de4b07..8b26269dc 100644 --- a/docs/extras/5tex/index.mdx +++ b/docs/extras/5tex/index.mdx @@ -112,6 +112,10 @@ lualatex sample.tex - `sample.pdf` という名前のファイルができるので、それを開く。 +:::tip +Mac を使っている場合は、バックスラッシュ( `\` )は、`Alt` を押しながら `¥` を押せば、打つことができます。 +::: + :::tip LuaLaTeX 以外も使うことができます。pLaTeX で jsarticle を使う例も載せておきます。