diff --git a/README.md b/README.md index 1d01a22..2d5a776 100644 --- a/README.md +++ b/README.md @@ -1,38 +1,41 @@

- - + +

----
-我是 周沫凡, [莫烦Python](https://morvanzhou.github.io/about/) 只是谐音, 我喜欢制作, -分享所学的东西, 所以你能在这里找到很多有用的东西, 少走弯路. 你能在[这里](https://morvanzhou.github.io/about/)找到关于我的所有东西. +我是 周沫凡, [莫烦Python](https://mofanpy.com/) 只是谐音, 我喜欢制作, +分享所学的东西, 所以你能在这里找到很多有用的东西, 少走弯路. 你能在[这里](https://mofanpy.com/about/)找到关于我的所有东西. ## 这个 Python tutorial 的一些内容: -* [Python 基础](https://morvanzhou.github.io/tutorials/python-basic/) - * [基础](https://morvanzhou.github.io/tutorials/python-basic/basic/) - * [多线程 threading](https://morvanzhou.github.io/tutorials/python-basic/threading/) - * [多进程 multiprocessing](https://morvanzhou.github.io/tutorials/python-basic/multiprocessing/) - * [简单窗口 tkinter](https://morvanzhou.github.io/tutorials/python-basic/tkinter/) -* [机器学习](https://morvanzhou.github.io/tutorials/machine-learning/) - * [有趣的机器学习](https://morvanzhou.github.io/tutorials/machine-learning/ML-intro/) - * [强化学习 (Reinforcement Learning)](https://morvanzhou.github.io/tutorials/machine-learning/reinforcement-learning/) - * [Tensorflow (神经网络)](https://morvanzhou.github.io/tutorials/machine-learning/tensorflow/) - * [PyTorch (神经网络)](https://morvanzhou.github.io/tutorials/machine-learning/torch/) - * [Theano (神经网络)](https://morvanzhou.github.io/tutorials/machine-learning/theano/) - * [Keras (快速神经网络)](https://morvanzhou.github.io/tutorials/machine-learning/keras/) - * [Scikit-Learn (机器学习)](https://morvanzhou.github.io/tutorials/machine-learning/sklearn/) -* [数据处理](https://morvanzhou.github.io/tutorials/data-manipulation/) - * [Numpy & Pandas (处理数据)](https://morvanzhou.github.io/tutorials/data-manipulation/np-pd/) - * [Matplotlib (绘图)](https://morvanzhou.github.io/tutorials/data-manipulation/plt/) -* [其他](https://morvanzhou.github.io/tutorials/others/) - * [Git (版本管理)](https://morvanzhou.github.io/tutorials/others/git/) +* [Python 基础](https://mofanpy.com/tutorials/python-basic/) + * [基础](https://mofanpy.com/tutorials/python-basic/basic/) + * [多线程 threading](https://mofanpy.com/tutorials/python-basic/threading/) + * [多进程 multiprocessing](https://mofanpy.com/tutorials/python-basic/multiprocessing/) + * [简单窗口 tkinter](https://mofanpy.com/tutorials/python-basic/tkinter/) +* [机器学习](https://mofanpy.com/tutorials/machine-learning/) + * [有趣的机器学习](https://mofanpy.com/tutorials/machine-learning/ML-intro/) + * [强化学习 (Reinforcement Learning)](https://mofanpy.com/tutorials/machine-learning/reinforcement-learning/) + * [进化算法 (Evolutionary Algorithm) 如遗传算法等](https://mofanpy.com/tutorials/machine-learning/evolutionary-algorithm/) + * [Tensorflow (神经网络)](https://mofanpy.com/tutorials/machine-learning/tensorflow/) + * [PyTorch (神经网络)](https://mofanpy.com/tutorials/machine-learning/torch/) + * [Theano (神经网络)](https://mofanpy.com/tutorials/machine-learning/theano/) + * [Keras (快速神经网络)](https://mofanpy.com/tutorials/machine-learning/keras/) + * [Scikit-Learn (机器学习)](https://mofanpy.com/tutorials/machine-learning/sklearn/) + * [机器学习实战](https://mofanpy.com/tutorials/machine-learning/ML-practice/) +* [数据处理](https://mofanpy.com/tutorials/data-manipulation/) + * [Numpy & Pandas (处理数据)](https://mofanpy.com/tutorials/data-manipulation/np-pd/) + * [Matplotlib (绘图)](https://mofanpy.com/tutorials/data-manipulation/plt/) + * [爬虫](https://mofanpy.com/tutorials/data-manipulation/scraping/) +* [其他](https://mofanpy.com/tutorials/others/) + * [Git (版本管理)](https://mofanpy.com/tutorials/others/git/) + * [Linux 简易教学](https://mofanpy.com/tutorials/others/linux-basic/) ## 赞助和支持 这些 tutorial 都是我用业余时间写出来, 录成视频, 如果你觉得它对你很有帮助, 请你也分享给需要学习的朋友们. -如果你看好我的经验分享, 也请考虑适当的 [赞助打赏](https://morvanzhou.github.io/support/), 让我能继续分享更好的内容给大家. \ No newline at end of file +如果你看好我的经验分享, 也请考虑适当的 [赞助打赏](https://mofanpy.com/support/), 让我能继续分享更好的内容给大家. \ No newline at end of file diff --git a/Reinforcement_learning_TUT/README.md b/Reinforcement_learning_TUT/README.md index 38fccff..773ed30 100644 --- a/Reinforcement_learning_TUT/README.md +++ b/Reinforcement_learning_TUT/README.md @@ -1,6 +1,6 @@

- +

@@ -10,11 +10,11 @@ # Note! This Reinforcement Learning Tutorial has been moved to anther independent repo: -[https://github.com/MorvanZhou/Reinforcement-learning-with-tensorflow](https://github.com/MorvanZhou/Reinforcement-learning-with-tensorflow) +[/MorvanZhou/Reinforcement-learning-with-tensorflow](/MorvanZhou/Reinforcement-learning-with-tensorflow) # 请注意! 这个 强化学习 的教程代码已经被移至另一个网页: -[https://github.com/MorvanZhou/Reinforcement-learning-with-tensorflow](https://github.com/MorvanZhou/Reinforcement-learning-with-tensorflow) +[/MorvanZhou/Reinforcement-learning-with-tensorflow](/MorvanZhou/Reinforcement-learning-with-tensorflow) # Donation @@ -31,7 +31,7 @@
- Patreon
diff --git a/basic/.ipynb_checkpoints/36_regex-checkpoint.ipynb b/basic/.ipynb_checkpoints/36_regex-checkpoint.ipynb new file mode 100644 index 0000000..984c91f --- /dev/null +++ b/basic/.ipynb_checkpoints/36_regex-checkpoint.ipynb @@ -0,0 +1,648 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Python 正则表达 RegEx" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 导入模块" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import re" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 简单 Python 匹配" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n", + "False\n" + ] + } + ], + "source": [ + "# matching string\n", + "pattern1 = \"cat\"\n", + "pattern2 = \"bird\"\n", + "string = \"dog runs to cat\"\n", + "print(pattern1 in string) \n", + "print(pattern2 in string) " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 用正则寻找配对" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "<_sre.SRE_Match object; span=(12, 15), match='cat'>\n", + "None\n" + ] + } + ], + "source": [ + "# regular expression\n", + "pattern1 = \"cat\"\n", + "pattern2 = \"bird\"\n", + "string = \"dog runs to cat\"\n", + "print(re.search(pattern1, string)) \n", + "print(re.search(pattern2, string)) " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 匹配多种可能 使用 []" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "<_sre.SRE_Match object; span=(4, 7), match='run'>\n" + ] + } + ], + "source": [ + "# multiple patterns (\"run\" or \"ran\")\n", + "ptn = r\"r[au]n\" \n", + "print(re.search(ptn, \"dog runs to cat\")) " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 匹配更多种可能" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "None\n", + "<_sre.SRE_Match object; span=(4, 7), match='run'>\n", + "<_sre.SRE_Match object; span=(4, 7), match='r2n'>\n", + "<_sre.SRE_Match object; span=(4, 7), match='run'>\n" + ] + } + ], + "source": [ + "# continue\n", + "print(re.search(r\"r[A-Z]n\", \"dog runs to cat\")) \n", + "print(re.search(r\"r[a-z]n\", \"dog runs to cat\")) \n", + "print(re.search(r\"r[0-9]n\", \"dog r2ns to cat\")) \n", + "print(re.search(r\"r[0-9a-z]n\", \"dog runs to cat\")) " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 特殊种类匹配" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 数字" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "<_sre.SRE_Match object; span=(4, 7), match='r4n'>\n", + "<_sre.SRE_Match object; span=(0, 3), match='run'>\n" + ] + } + ], + "source": [ + "# \\d : decimal digit\n", + "print(re.search(r\"r\\dn\", \"run r4n\")) \n", + "# \\D : any non-decimal digit\n", + "print(re.search(r\"r\\Dn\", \"run r4n\")) \n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 空白" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "<_sre.SRE_Match object; span=(0, 3), match='r\\nn'>\n", + "<_sre.SRE_Match object; span=(4, 7), match='r4n'>\n" + ] + } + ], + "source": [ + "# \\s : any white space [\\t\\n\\r\\f\\v]\n", + "print(re.search(r\"r\\sn\", \"r\\nn r4n\")) \n", + "# \\S : opposite to \\s, any non-white space\n", + "print(re.search(r\"r\\Sn\", \"r\\nn r4n\")) \n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 所有字母数字和\"_\"" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "<_sre.SRE_Match object; span=(4, 7), match='r4n'>\n", + "<_sre.SRE_Match object; span=(0, 3), match='r\\nn'>\n" + ] + } + ], + "source": [ + "# \\w : [a-zA-Z0-9_]\n", + "print(re.search(r\"r\\wn\", \"r\\nn r4n\")) \n", + "# \\W : opposite to \\w\n", + "print(re.search(r\"r\\Wn\", \"r\\nn r4n\")) \n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 空白字符" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "<_sre.SRE_Match object; span=(4, 8), match='runs'>\n", + "<_sre.SRE_Match object; span=(5, 11), match=' runs '>\n" + ] + } + ], + "source": [ + "# \\b : empty string (only at the start or end of the word)\n", + "print(re.search(r\"\\bruns\\b\", \"dog runs to cat\")) \n", + "# \\B : empty string (but not at the start or end of a word)\n", + "print(re.search(r\"\\B runs \\B\", \"dog runs to cat\")) \n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 特殊字符 任意字符" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "<_sre.SRE_Match object; span=(0, 5), match='runs\\\\'>\n", + "<_sre.SRE_Match object; span=(0, 3), match='r[n'>\n" + ] + } + ], + "source": [ + "# \\\\ : match \\\n", + "print(re.search(r\"runs\\\\\", \"runs\\ to me\")) \n", + "# . : match anything (except \\n)\n", + "print(re.search(r\"r.n\", \"r[ns to me\")) \n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 句尾句首" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "<_sre.SRE_Match object; span=(0, 3), match='dog'>\n", + "<_sre.SRE_Match object; span=(12, 15), match='cat'>\n" + ] + } + ], + "source": [ + "# ^ : match line beginning\n", + "print(re.search(r\"^dog\", \"dog runs to cat\")) \n", + "# $ : match line ending\n", + "print(re.search(r\"cat$\", \"dog runs to cat\")) \n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 是否" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "<_sre.SRE_Match object; span=(0, 6), match='Monday'>\n", + "<_sre.SRE_Match object; span=(0, 3), match='Mon'>\n" + ] + } + ], + "source": [ + "# ? : may or may not occur\n", + "print(re.search(r\"Mon(day)?\", \"Monday\")) \n", + "print(re.search(r\"Mon(day)?\", \"Mon\")) " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 多行匹配" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "None\n", + "<_sre.SRE_Match object; span=(18, 19), match='I'>\n" + ] + } + ], + "source": [ + "# multi-line\n", + "string = \"\"\"\n", + "dog runs to cat.\n", + "I run to dog.\n", + "\"\"\"\n", + "print(re.search(r\"^I\", string)) \n", + "print(re.search(r\"^I\", string, flags=re.M)) " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 0或多次" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "<_sre.SRE_Match object; span=(0, 1), match='a'>\n", + "<_sre.SRE_Match object; span=(0, 6), match='abbbbb'>\n" + ] + } + ], + "source": [ + "# * : occur 0 or more times\n", + "print(re.search(r\"ab*\", \"a\")) \n", + "print(re.search(r\"ab*\", \"abbbbb\")) \n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 1或多次" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "None\n", + "<_sre.SRE_Match object; span=(0, 6), match='abbbbb'>\n" + ] + } + ], + "source": [ + "# + : occur 1 or more times\n", + "print(re.search(r\"ab+\", \"a\")) \n", + "print(re.search(r\"ab+\", \"abbbbb\")) \n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 可选次数" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "None\n", + "<_sre.SRE_Match object; span=(0, 6), match='abbbbb'>\n" + ] + } + ], + "source": [ + "# {n, m} : occur n to m times\n", + "print(re.search(r\"ab{2,10}\", \"a\")) \n", + "print(re.search(r\"ab{2,10}\", \"abbbbb\")) \n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## group 组" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "021523, Date: Feb/12/2017\n", + "021523\n", + "Feb/12/2017\n" + ] + } + ], + "source": [ + "# group\n", + "match = re.search(r\"(\\d+), Date: (.+)\", \"ID: 021523, Date: Feb/12/2017\")\n", + "print(match.group()) \n", + "print(match.group(1)) \n", + "print(match.group(2)) " + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "021523\n", + "Feb/12/2017\n" + ] + } + ], + "source": [ + "match = re.search(r\"(?P\\d+), Date: (?P.+)\", \"ID: 021523, Date: Feb/12/2017\")\n", + "print(match.group('id')) \n", + "print(match.group('date')) " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 寻找所有匹配 " + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['run', 'ran']\n" + ] + } + ], + "source": [ + "# findall\n", + "print(re.findall(r\"r[ua]n\", \"run ran ren\")) " + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['run', 'ran']\n" + ] + } + ], + "source": [ + "# | : or\n", + "print(re.findall(r\"(run|ran)\", \"run ran ren\")) " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 替换" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "dog catches to cat\n" + ] + } + ], + "source": [ + "# re.sub() replace\n", + "print(re.sub(r\"r[au]ns\", \"catches\", \"dog runs to cat\")) " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 分裂" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['a', 'b', 'c', 'd', 'e']\n" + ] + } + ], + "source": [ + "# re.split()\n", + "print(re.split(r\"[,;\\.]\", \"a;b,c.d;e\")) \n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## compile" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "<_sre.SRE_Match object; span=(4, 7), match='ran'>\n" + ] + } + ], + "source": [ + "# compile\n", + "compiled_re = re.compile(r\"r[ua]n\")\n", + "print(compiled_re.search(\"dog ran to cat\")) " + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.5.1" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +} diff --git a/basic/35_set.py b/basic/35_set.py index 8df852b..31340da 100644 --- a/basic/35_set.py +++ b/basic/35_set.py @@ -10,17 +10,20 @@ print(set(char_list)) print(set(sentence)) -print(set([char_list, sentence])) +print(set(char_list + list(sentence))) unique_char = set(char_list) unique_char.add('x') -unique_char.add(['y', 'z']) +# unique_char.add(['y', 'z']) this is wrong print(unique_char) +unique_char.remove('x') +print(unique_char) +unique_char.discard('d') +print(unique_char) unique_char.clear() print(unique_char) -print(char_list.discard('d')) -print(char_list.remove('d')) -print(char_list.difference({'a', 'e', 'i'})) -print(char_list.intersection({'a', 'e', 'i'})) \ No newline at end of file +unique_char = set(char_list) +print(unique_char.difference({'a', 'e', 'i'})) +print(unique_char.intersection({'a', 'e', 'i'})) \ No newline at end of file diff --git a/basic/36_RegEx.py b/basic/36_RegEx.py new file mode 100644 index 0000000..b68dd3a --- /dev/null +++ b/basic/36_RegEx.py @@ -0,0 +1,110 @@ +import re + +# matching string +pattern1 = "cat" +pattern2 = "bird" +string = "dog runs to cat" +print(pattern1 in string) # True +print(pattern2 in string) # False + + +# regular expression +pattern1 = "cat" +pattern2 = "bird" +string = "dog runs to cat" +print(re.search(pattern1, string)) # <_sre.SRE_Match object; span=(12, 15), match='cat'> +print(re.search(pattern2, string)) # None + + +# multiple patterns ("run" or "ran") +ptn = r"r[au]n" # start with "r" means raw string +print(re.search(ptn, "dog runs to cat")) # <_sre.SRE_Match object; span=(4, 7), match='run'> + + +# continue +print(re.search(r"r[A-Z]n", "dog runs to cat")) # None +print(re.search(r"r[a-z]n", "dog runs to cat")) # <_sre.SRE_Match object; span=(4, 7), match='run'> +print(re.search(r"r[0-9]n", "dog r2ns to cat")) # <_sre.SRE_Match object; span=(4, 7), match='r2n'> +print(re.search(r"r[0-9a-z]n", "dog runs to cat")) # <_sre.SRE_Match object; span=(4, 7), match='run'> + + +# \d : decimal digit +print(re.search(r"r\dn", "run r4n")) # <_sre.SRE_Match object; span=(4, 7), match='r4n'> +# \D : any non-decimal digit +print(re.search(r"r\Dn", "run r4n")) # <_sre.SRE_Match object; span=(0, 3), match='run'> +# \s : any white space [\t\n\r\f\v] +print(re.search(r"r\sn", "r\nn r4n")) # <_sre.SRE_Match object; span=(0, 3), match='r\nn'> +# \S : opposite to \s, any non-white space +print(re.search(r"r\Sn", "r\nn r4n")) # <_sre.SRE_Match object; span=(4, 7), match='r4n'> +# \w : [a-zA-Z0-9_] +print(re.search(r"r\wn", "r\nn r4n")) # <_sre.SRE_Match object; span=(4, 7), match='r4n'> +# \W : opposite to \w +print(re.search(r"r\Wn", "r\nn r4n")) # <_sre.SRE_Match object; span=(0, 3), match='r\nn'> +# \b : empty string (only at the start or end of the word) +print(re.search(r"\bruns\b", "dog runs to cat")) # <_sre.SRE_Match object; span=(4, 8), match='runs'> +# \B : empty string (but not at the start or end of a word) +print(re.search(r"\B runs \B", "dog runs to cat")) # <_sre.SRE_Match object; span=(8, 14), match=' runs '> +# \\ : match \ +print(re.search(r"runs\\", "runs\ to me")) # <_sre.SRE_Match object; span=(0, 5), match='runs\\'> +# . : match anything (except \n) +print(re.search(r"r.n", "r[ns to me")) # <_sre.SRE_Match object; span=(0, 3), match='r[n'> +# ^ : match line beginning +print(re.search(r"^dog", "dog runs to cat")) # <_sre.SRE_Match object; span=(0, 3), match='dog'> +# $ : match line ending +print(re.search(r"cat$", "dog runs to cat")) # <_sre.SRE_Match object; span=(12, 15), match='cat'> +# ? : may or may not occur +print(re.search(r"Mon(day)?", "Monday")) # <_sre.SRE_Match object; span=(0, 6), match='Monday'> +print(re.search(r"Mon(day)?", "Mon")) # <_sre.SRE_Match object; span=(0, 3), match='Mon'> + + +# multi-line +string = """ +dog runs to cat. +I run to dog. +""" +print(re.search(r"^I", string)) # None +print(re.search(r"^I", string, flags=re.M)) # <_sre.SRE_Match object; span=(18, 19), match='I'> + + +# * : occur 0 or more times +print(re.search(r"ab*", "a")) # <_sre.SRE_Match object; span=(0, 1), match='a'> +print(re.search(r"ab*", "abbbbb")) # <_sre.SRE_Match object; span=(0, 6), match='abbbbb'> + +# + : occur 1 or more times +print(re.search(r"ab+", "a")) # None +print(re.search(r"ab+", "abbbbb")) # <_sre.SRE_Match object; span=(0, 6), match='abbbbb'> + +# {n, m} : occur n to m times +print(re.search(r"ab{2,10}", "a")) # None +print(re.search(r"ab{2,10}", "abbbbb")) # <_sre.SRE_Match object; span=(0, 6), match='abbbbb'> + + +# group +match = re.search(r"(\d+), Date: (.+)", "ID: 021523, Date: Feb/12/2017") +print(match.group()) # 021523, Date: Feb/12/2017 +print(match.group(1)) # 021523 +print(match.group(2)) # Date: Feb/12/2017 + +match = re.search(r"(?P\d+), Date: (?P.+)", "ID: 021523, Date: Feb/12/2017") +print(match.group('id')) # 021523 +print(match.group('date')) # Date: Feb/12/2017 + +# findall +print(re.findall(r"r[ua]n", "run ran ren")) # ['run', 'ran'] + +# | : or +print(re.findall(r"(run|ran)", "run ran ren")) # ['run', 'ran'] + +# re.sub() replace +print(re.sub(r"r[au]ns", "catches", "dog runs to cat")) # dog catches to cat + +# re.split() +print(re.split(r"[,;\.]", "a;b,c.d;e")) # ['a', 'b', 'c', 'd', 'e'] + + +# compile +compiled_re = re.compile(r"r[ua]n") +print(compiled_re.search("dog ran to cat")) # <_sre.SRE_Match object; span=(4, 7), match='ran'> + + + diff --git a/basic/36_regex.ipynb b/basic/36_regex.ipynb new file mode 100644 index 0000000..52aa22f --- /dev/null +++ b/basic/36_regex.ipynb @@ -0,0 +1,648 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Python 正则表达 RegEx" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 导入模块" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import re" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 简单 Python 匹配" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n", + "False\n" + ] + } + ], + "source": [ + "# matching string\n", + "pattern1 = \"cat\"\n", + "pattern2 = \"bird\"\n", + "string = \"dog runs to cat\"\n", + "print(pattern1 in string) \n", + "print(pattern2 in string) " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 用正则寻找配对" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "<_sre.SRE_Match object; span=(12, 15), match='cat'>\n", + "None\n" + ] + } + ], + "source": [ + "# regular expression\n", + "pattern1 = \"cat\"\n", + "pattern2 = \"bird\"\n", + "string = \"dog runs to cat\"\n", + "print(re.search(pattern1, string)) \n", + "print(re.search(pattern2, string)) " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 匹配多种可能 使用 []" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "<_sre.SRE_Match object; span=(4, 7), match='run'>\n" + ] + } + ], + "source": [ + "# multiple patterns (\"run\" or \"ran\")\n", + "ptn = r\"r[au]n\" \n", + "print(re.search(ptn, \"dog runs to cat\")) " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 匹配更多种可能" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "None\n", + "<_sre.SRE_Match object; span=(4, 7), match='run'>\n", + "<_sre.SRE_Match object; span=(4, 7), match='r2n'>\n", + "<_sre.SRE_Match object; span=(4, 7), match='run'>\n" + ] + } + ], + "source": [ + "# continue\n", + "print(re.search(r\"r[A-Z]n\", \"dog runs to cat\")) \n", + "print(re.search(r\"r[a-z]n\", \"dog runs to cat\")) \n", + "print(re.search(r\"r[0-9]n\", \"dog r2ns to cat\")) \n", + "print(re.search(r\"r[0-9a-z]n\", \"dog runs to cat\")) " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 特殊种类匹配" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 数字" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "<_sre.SRE_Match object; span=(4, 7), match='r4n'>\n", + "<_sre.SRE_Match object; span=(0, 3), match='run'>\n" + ] + } + ], + "source": [ + "# \\d : decimal digit\n", + "print(re.search(r\"r\\dn\", \"run r4n\")) \n", + "# \\D : any non-decimal digit\n", + "print(re.search(r\"r\\Dn\", \"run r4n\")) \n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 空白" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "<_sre.SRE_Match object; span=(0, 3), match='r\\nn'>\n", + "<_sre.SRE_Match object; span=(4, 7), match='r4n'>\n" + ] + } + ], + "source": [ + "# \\s : any white space [\\t\\n\\r\\f\\v]\n", + "print(re.search(r\"r\\sn\", \"r\\nn r4n\")) \n", + "# \\S : opposite to \\s, any non-white space\n", + "print(re.search(r\"r\\Sn\", \"r\\nn r4n\")) \n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 所有字母数字和\"_\"" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "<_sre.SRE_Match object; span=(4, 7), match='r4n'>\n", + "<_sre.SRE_Match object; span=(0, 3), match='r\\nn'>\n" + ] + } + ], + "source": [ + "# \\w : [a-zA-Z0-9_]\n", + "print(re.search(r\"r\\wn\", \"r\\nn r4n\")) \n", + "# \\W : opposite to \\w\n", + "print(re.search(r\"r\\Wn\", \"r\\nn r4n\")) \n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 空白字符" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "<_sre.SRE_Match object; span=(4, 8), match='runs'>\n", + "<_sre.SRE_Match object; span=(5, 11), match=' runs '>\n" + ] + } + ], + "source": [ + "# \\b : empty string (only at the start or end of the word)\n", + "print(re.search(r\"\\bruns\\b\", \"dog runs to cat\")) \n", + "# \\B : empty string (but not at the start or end of a word)\n", + "print(re.search(r\"\\B runs \\B\", \"dog runs to cat\")) \n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 特殊字符 任意字符" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "<_sre.SRE_Match object; span=(0, 5), match='runs\\\\'>\n", + "<_sre.SRE_Match object; span=(0, 3), match='r[n'>\n" + ] + } + ], + "source": [ + "# \\\\ : match \\\n", + "print(re.search(r\"runs\\\\\", \"runs\\ to me\")) \n", + "# . : match anything (except \\n)\n", + "print(re.search(r\"r.n\", \"r[ns to me\")) \n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 句尾句首" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "<_sre.SRE_Match object; span=(0, 3), match='dog'>\n", + "<_sre.SRE_Match object; span=(12, 15), match='cat'>\n" + ] + } + ], + "source": [ + "# ^ : match line beginning\n", + "print(re.search(r\"^dog\", \"dog runs to cat\")) \n", + "# $ : match line ending\n", + "print(re.search(r\"cat$\", \"dog runs to cat\")) \n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 是否" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "<_sre.SRE_Match object; span=(0, 6), match='Monday'>\n", + "<_sre.SRE_Match object; span=(0, 3), match='Mon'>\n" + ] + } + ], + "source": [ + "# ? : may or may not occur\n", + "print(re.search(r\"Mon(day)?\", \"Monday\")) \n", + "print(re.search(r\"Mon(day)?\", \"Mon\")) " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 多行匹配" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "None\n", + "<_sre.SRE_Match object; span=(18, 19), match='I'>\n" + ] + } + ], + "source": [ + "# multi-line\n", + "string = \"\"\"\n", + "dog runs to cat.\n", + "I run to dog.\n", + "\"\"\"\n", + "print(re.search(r\"^I\", string)) \n", + "print(re.search(r\"^I\", string, flags=re.M)) " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 0或多次" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "<_sre.SRE_Match object; span=(0, 1), match='a'>\n", + "<_sre.SRE_Match object; span=(0, 6), match='abbbbb'>\n" + ] + } + ], + "source": [ + "# * : occur 0 or more times\n", + "print(re.search(r\"ab*\", \"a\")) \n", + "print(re.search(r\"ab*\", \"abbbbb\")) \n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 1或多次" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "None\n", + "<_sre.SRE_Match object; span=(0, 6), match='abbbbb'>\n" + ] + } + ], + "source": [ + "# + : occur 1 or more times\n", + "print(re.search(r\"ab+\", \"a\")) \n", + "print(re.search(r\"ab+\", \"abbbbb\")) \n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 可选次数" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "None\n", + "<_sre.SRE_Match object; span=(0, 6), match='abbbbb'>\n" + ] + } + ], + "source": [ + "# {n, m} : occur n to m times\n", + "print(re.search(r\"ab{2,10}\", \"a\")) \n", + "print(re.search(r\"ab{2,10}\", \"abbbbb\")) \n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## group 组" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "021523, Date: Feb/12/2017\n", + "021523\n", + "Feb/12/2017\n" + ] + } + ], + "source": [ + "# group\n", + "match = re.search(r\"(\\d+), Date: (.+)\", \"ID: 021523, Date: Feb/12/2017\")\n", + "print(match.group()) \n", + "print(match.group(1)) \n", + "print(match.group(2)) " + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "021523\n", + "Feb/12/2017\n" + ] + } + ], + "source": [ + "match = re.search(r\"(?P\\d+), Date: (?P.+)\", \"ID: 021523, Date: Feb/12/2017\")\n", + "print(match.group('id')) \n", + "print(match.group('date')) " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 寻找所有匹配 " + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['run', 'ran']\n" + ] + } + ], + "source": [ + "# findall\n", + "print(re.findall(r\"r[ua]n\", \"run ran ren\")) " + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['run', 'ran']\n" + ] + } + ], + "source": [ + "# | : or\n", + "print(re.findall(r\"(run|ran)\", \"run ran ren\")) " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 替换" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "dog catches to cat\n" + ] + } + ], + "source": [ + "# re.sub() replace\n", + "print(re.sub(r\"r[au]ns\", \"catches\", \"dog runs to cat\")) " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 分裂" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['a', 'b', 'c', 'd', 'e']\n" + ] + } + ], + "source": [ + "# re.split()\n", + "print(re.split(r\"[,;\\.]\", \"a;b,c.d;e\")) \n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## compile" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "<_sre.SRE_Match object; span=(4, 7), match='ran'>\n" + ] + } + ], + "source": [ + "# compile\n", + "compiled_re = re.compile(r\"r[ua]n\")\n", + "print(compiled_re.search(\"dog ran to cat\")) " + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.5.1" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +} diff --git a/kerasTUT/10-save.py b/kerasTUT/10-save.py index 8838296..ff2670f 100644 --- a/kerasTUT/10-save.py +++ b/kerasTUT/10-save.py @@ -1,6 +1,6 @@ """ To know more or get code samples, please visit my website: -https://morvanzhou.github.io/tutorials/ +https://mofanpy.com/tutorials/ Or search: 莫烦Python Thank you for supporting! """ diff --git a/kerasTUT/2-installation.py b/kerasTUT/2-installation.py index 7c8c921..51765ef 100644 --- a/kerasTUT/2-installation.py +++ b/kerasTUT/2-installation.py @@ -1,6 +1,6 @@ """ To know more or get code samples, please visit my website: -https://morvanzhou.github.io/tutorials/ +https://mofanpy.com/tutorials/ Or search: 莫烦Python Thank you for supporting! """ diff --git a/kerasTUT/3-backend.py b/kerasTUT/3-backend.py index 93a68e9..8e7ee00 100644 --- a/kerasTUT/3-backend.py +++ b/kerasTUT/3-backend.py @@ -1,6 +1,6 @@ """ To know more or get code samples, please visit my website: -https://morvanzhou.github.io/tutorials/ +https://mofanpy.com/tutorials/ Or search: 莫烦Python Thank you for supporting! """ diff --git a/kerasTUT/4-regressor_example.py b/kerasTUT/4-regressor_example.py index e41e2ad..2af1e03 100644 --- a/kerasTUT/4-regressor_example.py +++ b/kerasTUT/4-regressor_example.py @@ -1,6 +1,6 @@ """ To know more or get code samples, please visit my website: -https://morvanzhou.github.io/tutorials/ +https://mofanpy.com/tutorials/ Or search: 莫烦Python Thank you for supporting! """ diff --git a/kerasTUT/5-classifier_example.py b/kerasTUT/5-classifier_example.py index 20cecb3..9e744c6 100644 --- a/kerasTUT/5-classifier_example.py +++ b/kerasTUT/5-classifier_example.py @@ -1,6 +1,6 @@ """ To know more or get code samples, please visit my website: -https://morvanzhou.github.io/tutorials/ +https://mofanpy.com/tutorials/ Or search: 莫烦Python Thank you for supporting! """ diff --git a/kerasTUT/6-CNN_example.py b/kerasTUT/6-CNN_example.py index 05ff0bc..eda3ec8 100644 --- a/kerasTUT/6-CNN_example.py +++ b/kerasTUT/6-CNN_example.py @@ -1,6 +1,6 @@ """ To know more or get code samples, please visit my website: -https://morvanzhou.github.io/tutorials/ +https://mofanpy.com/tutorials/ Or search: 莫烦Python Thank you for supporting! """ @@ -23,7 +23,7 @@ from keras.optimizers import Adam # download the mnist to the path '~/.keras/datasets/' if it is the first time to be called -# X shape (60,000 28x28), y shape (10,000, ) +# training X shape (60000, 28x28), Y shape (60000, ). test X shape (10000, 28x28), Y shape (10000, ) (X_train, y_train), (X_test, y_test) = mnist.load_data() # data pre-processing @@ -37,7 +37,7 @@ # Conv layer 1 output shape (32, 28, 28) model.add(Convolution2D( - batch_input_shape=(64, 1, 28, 28), + batch_input_shape=(None, 1, 28, 28), filters=32, kernel_size=5, strides=1, diff --git a/kerasTUT/7-RNN_Classifier_example.py b/kerasTUT/7-RNN_Classifier_example.py index 92001df..368c357 100644 --- a/kerasTUT/7-RNN_Classifier_example.py +++ b/kerasTUT/7-RNN_Classifier_example.py @@ -1,6 +1,6 @@ """ To know more or get code samples, please visit my website: -https://morvanzhou.github.io/tutorials/ +https://mofanpy.com/tutorials/ Or search: 莫烦Python Thank you for supporting! """ diff --git a/kerasTUT/8-RNN_LSTM_Regressor_example.py b/kerasTUT/8-RNN_LSTM_Regressor_example.py index 0b6581d..83aee5e 100644 --- a/kerasTUT/8-RNN_LSTM_Regressor_example.py +++ b/kerasTUT/8-RNN_LSTM_Regressor_example.py @@ -1,6 +1,6 @@ """ To know more or get code samples, please visit my website: -https://morvanzhou.github.io/tutorials/ +https://mofanpy.com/tutorials/ Or search: 莫烦Python Thank you for supporting! """ diff --git a/kerasTUT/9-Autoencoder_example.py b/kerasTUT/9-Autoencoder_example.py index 2cf8cce..754c2bd 100644 --- a/kerasTUT/9-Autoencoder_example.py +++ b/kerasTUT/9-Autoencoder_example.py @@ -1,6 +1,6 @@ """ To know more or get code samples, please visit my website: -https://morvanzhou.github.io/tutorials/ +https://mofanpy.com/tutorials/ Or search: 莫烦Python Thank you for supporting! """ diff --git a/kerasTUT/README.md b/kerasTUT/README.md index 55f37c4..0427e98 100644 --- a/kerasTUT/README.md +++ b/kerasTUT/README.md @@ -2,19 +2,19 @@ In these tutorials for Tensorflow, we will build our first Neural Network and try to build some advanced Neural Network architectures developed recent years. -All methods mentioned below have their video and text tutorial in Chinese. Visit [莫烦 Python](https://morvanzhou.github.io/tutorials/) for more. +All methods mentioned below have their video and text tutorial in Chinese. Visit [莫烦 Python](https://mofanpy.com/) for more. If you speak Chinese, you can watch my [Youtube channel](https://www.youtube.com/channel/UCdyjiB5H8Pu7aDTNVXTTpcg) as well. -* [Install](https://github.com/MorvanZhou/tutorials/blob/master/kerasTUT/2-installation.py) -* [Backend (Tensorflow/Theano)](https://github.com/MorvanZhou/tutorials/blob/master/kerasTUT/3-backend.py) +* [Install](2-installation.py) +* [Backend (Tensorflow/Theano)](3-backend.py) * Networks - * [Simple Regressor](https://github.com/MorvanZhou/tutorials/blob/master/kerasTUT/4-regressor_example.py) - * [Simple Classifier](https://github.com/MorvanZhou/tutorials/blob/master/kerasTUT/5-classifier_example.py) - * [CNN](https://github.com/MorvanZhou/tutorials/blob/master/kerasTUT/6-CNN_example.py) - * [RNN classifier](https://github.com/MorvanZhou/tutorials/blob/master/kerasTUT/7-RNN_Classifier_example.py) - * [RNN LSTM regressor](https://github.com/MorvanZhou/tutorials/blob/master/kerasTUT/8-RNN_LSTM_Regressor_example.py) - * [Autoencoder](https://github.com/MorvanZhou/tutorials/blob/master/kerasTUT/9-Autoencoder_example.py) + * [Simple Regressor](4-regressor_example.py) + * [Simple Classifier](5-classifier_example.py) + * [CNN](6-CNN_example.py) + * [RNN classifier](7-RNN_Classifier_example.py) + * [RNN LSTM regressor](8-RNN_LSTM_Regressor_example.py) + * [Autoencoder](9-Autoencoder_example.py) # Donation @@ -31,7 +31,7 @@ If you speak Chinese, you can watch my [Youtube channel](https://www.youtube.com \ No newline at end of file diff --git a/matplotlibTUT/README.md b/matplotlibTUT/README.md index b260de2..5dbf09e 100644 --- a/matplotlibTUT/README.md +++ b/matplotlibTUT/README.md @@ -1,50 +1,50 @@ # Python Matplotlib methods and tutorials -All methods mentioned below have their video and text tutorial in Chinese. Visit [莫烦 Python](https://morvanzhou.github.io/tutorials/) for more. +All methods mentioned below have their video and text tutorial in Chinese. Visit [莫烦 Python](https://mofanpy.com/tutorials/) for more. -* [Install](https://github.com/MorvanZhou/tutorials/blob/master/matplotlibTUT/plt2_install.py) -* [Basic usage](https://github.com/MorvanZhou/tutorials/blob/master/matplotlibTUT/plt3_simple_plot.py) - * [Figure](https://github.com/MorvanZhou/tutorials/blob/master/matplotlibTUT/plt4_figure.py) - * [Axis setting1](https://github.com/MorvanZhou/tutorials/blob/master/matplotlibTUT/plt5_ax_setting1.py) - * [Axis setting2](https://github.com/MorvanZhou/tutorials/blob/master/matplotlibTUT/plt6_ax_setting2.py) - * [Legend](https://github.com/MorvanZhou/tutorials/blob/master/matplotlibTUT/plt7_legend.py) - * [Annotation](https://github.com/MorvanZhou/tutorials/blob/master/matplotlibTUT/plt8_annotation.py) - * [Deal with Tick](https://github.com/MorvanZhou/tutorials/blob/master/matplotlibTUT/plt9_tick_visibility.py) +* [Install](plt2_install.py) +* [Basic usage](plt3_simple_plot.py) + * [Figure](plt4_figure.py) + * [Axis setting1](plt5_ax_setting1.py) + * [Axis setting2](plt6_ax_setting2.py) + * [Legend](plt7_legend.py) + * [Annotation](plt8_annotation.py) + * [Deal with Tick](plt9_tick_visibility.py) * Drawing - * [Scatter](https://github.com/MorvanZhou/tutorials/blob/master/matplotlibTUT/plt10_scatter.py) - * [Bar](https://github.com/MorvanZhou/tutorials/blob/master/matplotlibTUT/plt11_bar.py) - * [Contours](https://github.com/MorvanZhou/tutorials/blob/master/matplotlibTUT/plt12_contours.py) - * [Image](https://github.com/MorvanZhou/tutorials/blob/master/matplotlibTUT/plt13_image.py) - * [3D plot](https://github.com/MorvanZhou/tutorials/blob/master/matplotlibTUT/plt14_3d.py) + * [Scatter](plt10_scatter.py) + * [Bar](plt11_bar.py) + * [Contours](plt12_contours.py) + * [Image](plt13_image.py) + * [3D plot](plt14_3d.py) * Subplots - * [Subplot1](https://github.com/MorvanZhou/tutorials/blob/master/matplotlibTUT/plt15_subplot.py) - * [Grid Subplot](https://github.com/MorvanZhou/tutorials/blob/master/matplotlibTUT/plt16_grid_subplot.py) - * [Plot in Plot](https://github.com/MorvanZhou/tutorials/blob/master/matplotlibTUT/plt17_plot_in_plot.py) - * [Second y-axis](https://github.com/MorvanZhou/tutorials/blob/master/matplotlibTUT/plt18_secondary_yaxis.py) + * [Subplot1](plt15_subplot.py) + * [Grid Subplot](plt16_grid_subplot.py) + * [Plot in Plot](plt17_plot_in_plot.py) + * [Second y-axis](plt18_secondary_yaxis.py) * Animation - * [Function Animation](https://github.com/MorvanZhou/tutorials/blob/master/matplotlibTUT/plt19_animation.py) + * [Function Animation](plt19_animation.py) # Some plots from these tutorials: -![axis setting](https://morvanzhou.github.io/static/results/plt/2_4_3.png) +![axis setting](https://mofanpy.com/static/results/plt/2_4_3.png) -![Annotation](https://morvanzhou.github.io/static/results/plt/2_6_5.png) +![Annotation](https://mofanpy.com/static/results/plt/2_6_5.png) -![Scatter](https://morvanzhou.github.io/static/results/plt/3_1_1.png) +![Scatter](https://mofanpy.com/static/results/plt/3_1_1.png) -![Bars](https://morvanzhou.github.io/static/results/plt/3_2_1.png) +![Bars](https://mofanpy.com/static/results/plt/3_2_1.png) -![Contours](https://morvanzhou.github.io/static/results/plt/3_3_1.png) +![Contours](https://mofanpy.com/static/results/plt/3_3_1.png) -![Image](https://morvanzhou.github.io/static/results/plt/3_4_1.png) +![Image](https://mofanpy.com/static/results/plt/3_4_1.png) -![3D plot](https://morvanzhou.github.io/static/results/plt/3_5_1.png) +![3D plot](https://mofanpy.com/static/results/plt/3_5_1.png) -![Subplot](https://morvanzhou.github.io/static/results/plt/4_1_2.png) +![Subplot](https://mofanpy.com/static/results/plt/4_1_2.png) -![plot in plot](https://morvanzhou.github.io/static/results/plt/4_3_1.png) +![plot in plot](https://mofanpy.com/static/results/plt/4_3_1.png) # Donation @@ -60,7 +60,7 @@ All methods mentioned below have their video and text tutorial in Chinese. Visit \ No newline at end of file diff --git a/matplotlibTUT/plt7_legend.py b/matplotlibTUT/plt7_legend.py index 40051ca..1f690c3 100644 --- a/matplotlibTUT/plt7_legend.py +++ b/matplotlibTUT/plt7_legend.py @@ -30,11 +30,11 @@ plt.yticks([-2, -1.8, -1, 1.22, 3], [r'$really\ bad$', r'$bad$', r'$normal$', r'$good$', r'$really\ good$']) -l1, = plt.plot(x, y2, label='linear line') -l2, = plt.plot(x, y1, color='red', linewidth=1.0, linestyle='--', label='square line') +l1, = plt.plot(x, y1, label='linear line') +l2, = plt.plot(x, y2, color='red', linewidth=1.0, linestyle='--', label='square line') -# plt.legend(loc='upper right') -plt.legend(handles=[l1, l2], labels=['up', 'down'], loc='best') +plt.legend(loc='upper right') +# plt.legend(handles=[l1, l2], labels=['up', 'down'], loc='best') # the "," is very important in here l1, = plt... and l2, = plt... for this step """legend( handles=(line1, line2, line3), labels=('label1', 'label2', 'label3'), diff --git a/matplotlibTUT/plt9_tick_visibility.py b/matplotlibTUT/plt9_tick_visibility.py index c0ec70e..a43fffd 100644 --- a/matplotlibTUT/plt9_tick_visibility.py +++ b/matplotlibTUT/plt9_tick_visibility.py @@ -18,7 +18,7 @@ y = 0.1*x plt.figure() -plt.plot(x, y, linewidth=10) +plt.plot(x, y, linewidth=10, zorder=1) # set zorder for ordering the plot in plt 2.0.2 or higher plt.ylim(-2, 2) ax = plt.gca() ax.spines['right'].set_color('none') @@ -32,5 +32,6 @@ for label in ax.get_xticklabels() + ax.get_yticklabels(): label.set_fontsize(12) - label.set_bbox(dict(facecolor='white', edgecolor='None', alpha=0.7)) + # set zorder for ordering the plot in plt 2.0.2 or higher + label.set_bbox(dict(facecolor='white', edgecolor='none', alpha=0.8, zorder=2)) plt.show() diff --git a/pyTorch tutorial/README.md b/pyTorch tutorial/README.md index b26a2ce..660a0c8 100644 --- a/pyTorch tutorial/README.md +++ b/pyTorch tutorial/README.md @@ -1,6 +1,6 @@

- +

@@ -10,11 +10,11 @@ # This pyTorch Tutorial has been moved to anther independent repo: -[https://github.com/MorvanZhou/PyTorch-Tutorial](https://github.com/MorvanZhou/PyTorch-Tutorial) +[/MorvanZhou/PyTorch-Tutorial](/MorvanZhou/PyTorch-Tutorial) # 请注意, 这个 PyTorch 的教程代码已经被移至另一个网页: -[https://github.com/MorvanZhou/PyTorch-Tutorial](https://github.com/MorvanZhou/PyTorch-Tutorial) +[/MorvanZhou/PyTorch-Tutorial](/MorvanZhou/PyTorch-Tutorial) # Donation @@ -31,7 +31,7 @@ diff --git a/tensorflowTUT/README.md b/tensorflowTUT/README.md index 934e55a..2637277 100644 --- a/tensorflowTUT/README.md +++ b/tensorflowTUT/README.md @@ -1,6 +1,6 @@

- +

@@ -14,38 +14,38 @@ In these tutorials for Tensorflow, we will build our first Neural Network and try to build some advanced Neural Network architectures developed recent years. -All methods mentioned below have their video and text tutorial in Chinese. Visit [莫烦 Python](https://morvanzhou.github.io/tutorials/) for more. +All methods mentioned below have their video and text tutorial in Chinese. Visit [莫烦 Python](https://mofanpy.com/tutorials/) for more. If you speak Chinese, you can watch my [Youtube channel](https://www.youtube.com/channel/UCdyjiB5H8Pu7aDTNVXTTpcg) as well. **As many requests about making these tutorials available in English, please find them in this playlist:** ([https://www.youtube.com/playlist?list=PLXO45tsB95cJHXaDKpbwr5fC_CCYylw1f](https://www.youtube.com/playlist?list=PLXO45tsB95cJHXaDKpbwr5fC_CCYylw1f)) * Tensorflow Basic - * [Basic example](https://github.com/MorvanZhou/tutorials/blob/master/tensorflowTUT/tf5_example2/full_code.py) - * [Session](https://github.com/MorvanZhou/tutorials/blob/master/tensorflowTUT/tensorflow6_session.py) - * [Variable](https://github.com/MorvanZhou/tutorials/blob/master/tensorflowTUT/tensorflow7_variable.py) - * [Placeholder](https://github.com/MorvanZhou/tutorials/blob/master/tensorflowTUT/tensorflow8_feeds.py) + * [Basic example](tf5_example2/full_code.py) + * [Session](tensorflow6_session.py) + * [Variable](tensorflow7_variable.py) + * [Placeholder](tensorflow8_feeds.py) * Build your first NN - * [Adding layer](https://github.com/MorvanZhou/tutorials/blob/master/tensorflowTUT/tensorflow10_def_add_layer.py) - * [Build NN](https://github.com/MorvanZhou/tutorials/blob/master/tensorflowTUT/tf11_build_network/full_code.py) - * [Visualize update](https://github.com/MorvanZhou/tutorials/blob/master/tensorflowTUT/tf12_plot_result/full_code.py) + * [Adding layer](tensorflow10_def_add_layer.py) + * [Build NN](tf11_build_network/full_code.py) + * [Visualize update](tf12_plot_result/full_code.py) * Tensorboard - * [Visualization 1](https://github.com/MorvanZhou/tutorials/blob/master/tensorflowTUT/tf14_tensorboard/full_code.py) - * [Visualization 2](https://github.com/MorvanZhou/tutorials/blob/master/tensorflowTUT/tf15_tensorboard/full_code.py) -* [Classification](https://github.com/MorvanZhou/tutorials/blob/master/tensorflowTUT/tf16_classification/full_code.py) -* [Overfitting and dropout](https://github.com/MorvanZhou/tutorials/blob/master/tensorflowTUT/tf17_dropout/full_code.py) -* [Save Network](https://github.com/MorvanZhou/tutorials/blob/master/tensorflowTUT/tf19_saver.py) + * [Visualization 1](tf14_tensorboard/full_code.py) + * [Visualization 2](tf15_tensorboard/full_code.py) +* [Classification](tf16_classification/full_code.py) +* [Overfitting and dropout](tf17_dropout/full_code.py) +* [Save Network](tf19_saver.py) * CNN - * [CNN layers](https://github.com/MorvanZhou/tutorials/blob/master/tensorflowTUT/tf18_CNN2/full_code.py) - * [CNN training](https://github.com/MorvanZhou/tutorials/blob/master/tensorflowTUT/tf18_CNN3/full_code.py) + * [CNN layers](tf18_CNN2/full_code.py) + * [CNN training](tf18_CNN3/full_code.py) * RNN - * [Classification](https://github.com/MorvanZhou/tutorials/blob/master/tensorflowTUT/tf20_RNN2/full_code.py) - * [Regression](https://github.com/MorvanZhou/tutorials/blob/master/tensorflowTUT/tf20_RNN2.2/full_code.py) -* [Autoencoder](https://github.com/MorvanZhou/tutorials/blob/master/tensorflowTUT/tf21_autoencoder/full_code.py) + * [Classification](tf20_RNN2/full_code.py) + * [Regression](tf20_RNN2.2/full_code.py) +* [Autoencoder](tf21_autoencoder/full_code.py) * Scope - * [Scope in TF](https://github.com/MorvanZhou/tutorials/blob/master/tensorflowTUT/tf22_scope/tf22_scope.py) - * [Training Testing for RNN](https://github.com/MorvanZhou/tutorials/blob/master/tensorflowTUT/tf22_scope/tf22_RNN_scope.py) -* [Batch Normalization](https://github.com/MorvanZhou/tutorials/blob/master/tensorflowTUT/tf23_BN/tf23_BN.py) + * [Scope in TF](tf22_scope/tf22_scope.py) + * [Training Testing for RNN](tf22_scope/tf22_RNN_scope.py) +* [Batch Normalization](tf23_BN/tf23_BN.py) @@ -63,7 +63,7 @@ If you speak Chinese, you can watch my [Youtube channel](https://www.youtube.com diff --git a/tensorflowTUT/tf15_tensorboard/logs/events.out.tfevents.1494075549.Morvan b/tensorflowTUT/tf15_tensorboard/logs/events.out.tfevents.1494075549.Morvan new file mode 100644 index 0000000..561ea24 Binary files /dev/null and b/tensorflowTUT/tf15_tensorboard/logs/events.out.tfevents.1494075549.Morvan differ diff --git a/tensorflowTUT/tf20_RNN2.2/full_code.py b/tensorflowTUT/tf20_RNN2.2/full_code.py index 6e1b4bc..7157bb7 100644 --- a/tensorflowTUT/tf20_RNN2.2/full_code.py +++ b/tensorflowTUT/tf20_RNN2.2/full_code.py @@ -100,7 +100,8 @@ def compute_cost(self): name='average_cost') tf.summary.scalar('cost', self.cost) - def ms_error(self, labels, logits): + @staticmethod + def ms_error(labels, logits): return tf.square(tf.subtract(labels, logits)) def _weight_variable(self, shape, name='weights'): diff --git a/tensorflowTUT/tf20_RNN2.2/logs/events.out.tfevents.1490697566.Morvan b/tensorflowTUT/tf20_RNN2.2/logs/events.out.tfevents.1490697566.Morvan new file mode 100644 index 0000000..f00f316 Binary files /dev/null and b/tensorflowTUT/tf20_RNN2.2/logs/events.out.tfevents.1490697566.Morvan differ diff --git a/tensorflowTUT/tf20_RNN2.2/logs/events.out.tfevents.1490697588.Morvan b/tensorflowTUT/tf20_RNN2.2/logs/events.out.tfevents.1490697588.Morvan new file mode 100644 index 0000000..b2499d1 Binary files /dev/null and b/tensorflowTUT/tf20_RNN2.2/logs/events.out.tfevents.1490697588.Morvan differ diff --git a/tensorflowTUT/tf20_RNN2.2/logs/events.out.tfevents.1493818356.Morvan b/tensorflowTUT/tf20_RNN2.2/logs/events.out.tfevents.1493818356.Morvan new file mode 100644 index 0000000..8ac8cb2 Binary files /dev/null and b/tensorflowTUT/tf20_RNN2.2/logs/events.out.tfevents.1493818356.Morvan differ diff --git a/tensorflowTUT/tf20_RNN2.2/logs/events.out.tfevents.1493818411.Morvan b/tensorflowTUT/tf20_RNN2.2/logs/events.out.tfevents.1493818411.Morvan new file mode 100644 index 0000000..13dd514 Binary files /dev/null and b/tensorflowTUT/tf20_RNN2.2/logs/events.out.tfevents.1493818411.Morvan differ diff --git a/tensorflowTUT/tf20_RNN2.2/logs/events.out.tfevents.1493818762.Morvan b/tensorflowTUT/tf20_RNN2.2/logs/events.out.tfevents.1493818762.Morvan new file mode 100644 index 0000000..e790ee0 Binary files /dev/null and b/tensorflowTUT/tf20_RNN2.2/logs/events.out.tfevents.1493818762.Morvan differ diff --git a/tensorflowTUT/tf20_RNN2.2/logs/events.out.tfevents.1509756112.Morvan b/tensorflowTUT/tf20_RNN2.2/logs/events.out.tfevents.1509756112.Morvan new file mode 100644 index 0000000..7b9ae16 Binary files /dev/null and b/tensorflowTUT/tf20_RNN2.2/logs/events.out.tfevents.1509756112.Morvan differ diff --git a/tensorflowTUT/tf20_RNN2.2/logs/events.out.tfevents.1509756156.Morvan b/tensorflowTUT/tf20_RNN2.2/logs/events.out.tfevents.1509756156.Morvan new file mode 100644 index 0000000..6988176 Binary files /dev/null and b/tensorflowTUT/tf20_RNN2.2/logs/events.out.tfevents.1509756156.Morvan differ diff --git a/tensorflowTUT/tf20_RNN2/MNIST_data/t10k-images-idx3-ubyte.gz b/tensorflowTUT/tf20_RNN2/MNIST_data/t10k-images-idx3-ubyte.gz new file mode 100644 index 0000000..5ace8ea Binary files /dev/null and b/tensorflowTUT/tf20_RNN2/MNIST_data/t10k-images-idx3-ubyte.gz differ diff --git a/tensorflowTUT/tf20_RNN2/MNIST_data/t10k-labels-idx1-ubyte.gz b/tensorflowTUT/tf20_RNN2/MNIST_data/t10k-labels-idx1-ubyte.gz new file mode 100644 index 0000000..a7e1415 Binary files /dev/null and b/tensorflowTUT/tf20_RNN2/MNIST_data/t10k-labels-idx1-ubyte.gz differ diff --git a/tensorflowTUT/tf20_RNN2/MNIST_data/train-images-idx3-ubyte.gz b/tensorflowTUT/tf20_RNN2/MNIST_data/train-images-idx3-ubyte.gz new file mode 100644 index 0000000..b50e4b6 Binary files /dev/null and b/tensorflowTUT/tf20_RNN2/MNIST_data/train-images-idx3-ubyte.gz differ diff --git a/tensorflowTUT/tf20_RNN2/MNIST_data/train-labels-idx1-ubyte.gz b/tensorflowTUT/tf20_RNN2/MNIST_data/train-labels-idx1-ubyte.gz new file mode 100644 index 0000000..707a576 Binary files /dev/null and b/tensorflowTUT/tf20_RNN2/MNIST_data/train-labels-idx1-ubyte.gz differ diff --git a/tensorflowTUT/tf21_autoencoder/full_code.py b/tensorflowTUT/tf21_autoencoder/full_code.py index 4705b23..10097ce 100644 --- a/tensorflowTUT/tf21_autoencoder/full_code.py +++ b/tensorflowTUT/tf21_autoencoder/full_code.py @@ -1,6 +1,6 @@ # View more python learning tutorial on my Youtube and Youku channel!!! -# My tutorial website: https://morvanzhou.github.io/tutorials/ +# My tutorial website: https://mofanpy.com/tutorials/ from __future__ import division, print_function, absolute_import diff --git a/tensorflowTUT/tf22_scope/tf22_RNN_scope.py b/tensorflowTUT/tf22_scope/tf22_RNN_scope.py index d816b48..15715c9 100644 --- a/tensorflowTUT/tf22_scope/tf22_RNN_scope.py +++ b/tensorflowTUT/tf22_scope/tf22_RNN_scope.py @@ -1,4 +1,4 @@ -# visit https://morvanzhou.github.io/tutorials/ for more! +# visit https://mofanpy.com/tutorials/ for more! # 22 scope (name_scope/variable_scope) diff --git a/tensorflowTUT/tf22_scope/tf22_scope.py b/tensorflowTUT/tf22_scope/tf22_scope.py index 0906957..c7972b0 100644 --- a/tensorflowTUT/tf22_scope/tf22_scope.py +++ b/tensorflowTUT/tf22_scope/tf22_scope.py @@ -1,4 +1,4 @@ -# visit https://morvanzhou.github.io/tutorials/ for more! +# visit https://mofanpy.com/tutorials/ for more! # 22 scope (name_scope/variable_scope) diff --git a/tensorflowTUT/tf23_BN/tf23_BN.py b/tensorflowTUT/tf23_BN/tf23_BN.py index 592462b..bb46188 100644 --- a/tensorflowTUT/tf23_BN/tf23_BN.py +++ b/tensorflowTUT/tf23_BN/tf23_BN.py @@ -1,5 +1,5 @@ """ -visit https://morvanzhou.github.io/tutorials/ for more! +visit https://mofanpy.com/tutorials/ for more! Build two networks. 1. Without batch normalization diff --git a/tensorflowTUT/tf5_example2/full_code.py b/tensorflowTUT/tf5_example2/full_code.py index 4a857be..6b1a9ee 100644 --- a/tensorflowTUT/tf5_example2/full_code.py +++ b/tensorflowTUT/tf5_example2/full_code.py @@ -23,8 +23,6 @@ loss = tf.reduce_mean(tf.square(y-y_data)) optimizer = tf.train.GradientDescentOptimizer(0.5) train = optimizer.minimize(loss) - -init = tf.initialize_all_variables() ### create tensorflow structure end ### sess = tf.Session() diff --git a/theanoTUT/README.md b/theanoTUT/README.md index cc4161f..18c4c6d 100644 --- a/theanoTUT/README.md +++ b/theanoTUT/README.md @@ -1,22 +1,22 @@ # Python Theano methods and tutorials -All methods mentioned below have their video and text tutorial in Chinese. Visit [莫烦 Python](https://morvanzhou.github.io/tutorials/) for more. +All methods mentioned below have their video and text tutorial in Chinese. Visit [莫烦 Python](https://mofanpy.com/tutorials/) for more. -* [Install](https://github.com/MorvanZhou/tutorials/blob/master/theanoTUT/theano2_install.py) -* [Example of Machine Learning](https://github.com/MorvanZhou/tutorials/blob/master/theanoTUT/theano3_what_does_ML_do.py) +* [Install](theano2_install.py) +* [Example of Machine Learning](theano3_what_does_ML_do.py) * Basic - * [Basic Usage](https://github.com/MorvanZhou/tutorials/blob/master/theanoTUT/theano4_basic_usage.py) - * [Function](https://github.com/MorvanZhou/tutorials/blob/master/theanoTUT/theano5_function.py) - * [Shared Variable](https://github.com/MorvanZhou/tutorials/blob/master/theanoTUT/theano6_shared_variable.py) - * [Activation Function](https://github.com/MorvanZhou/tutorials/blob/master/theanoTUT/theano7_activation_function.py) + * [Basic Usage](theano4_basic_usage.py) + * [Function](theano5_function.py) + * [Shared Variable](theano6_shared_variable.py) + * [Activation Function](theano7_activation_function.py) * Build a Network - * [Layer](https://github.com/MorvanZhou/tutorials/blob/master/theanoTUT/theano8_Layer_class.py) - * [Regression](https://github.com/MorvanZhou/tutorials/blob/master/theanoTUT/theano9_regression_nn/full_code.py) - * [Visualize Regression](https://github.com/MorvanZhou/tutorials/blob/master/theanoTUT/theano10_regression_visualization/full_code.py) - * [Classification](https://github.com/MorvanZhou/tutorials/blob/master/theanoTUT/theano11_classification_nn/full_code.py) - * [Regularization](https://github.com/MorvanZhou/tutorials/tree/master/theanoTUT/theano12_regularization) - * [Save model](https://github.com/MorvanZhou/tutorials/blob/master/theanoTUT/theano13_save/full_code.py) + * [Layer](theano8_Layer_class.py) + * [Regression](theano9_regression_nn/full_code.py) + * [Visualize Regression](theano10_regression_visualization/full_code.py) + * [Classification](theano11_classification_nn/full_code.py) + * [Regularization](https://github.com/MorvanZhou/tutorials/tree/master/theano12_regularization) + * [Save model](theano13_save/full_code.py) # Donation @@ -32,7 +32,7 @@ All methods mentioned below have their video and text tutorial in Chinese. Visit \ No newline at end of file diff --git a/tkinterTUT/ins.gif b/tkinterTUT/ins.gif new file mode 100644 index 0000000..76ad3be Binary files /dev/null and b/tkinterTUT/ins.gif differ diff --git a/tkinterTUT/tk11_msgbox.py b/tkinterTUT/tk11_msgbox.py index 10f4441..bf54615 100644 --- a/tkinterTUT/tk11_msgbox.py +++ b/tkinterTUT/tk11_msgbox.py @@ -4,15 +4,16 @@ # Youku video tutorial: http://i.youku.com/pythontutorial import tkinter as tk +import tkinter.messagebox window = tk.Tk() window.title('my window') window.geometry('200x200') def hit_me(): - #tk.messagebox.showinfo(title='Hi', message='hahahaha') - #tk.messagebox.showwarning(title='Hi', message='nononono') - #tk.messagebox.showerror(title='Hi', message='No!! never') + #tk.messagebox.showinfo(title='Hi', message='hahahaha') # return 'ok' + #tk.messagebox.showwarning(title='Hi', message='nononono') # return 'ok' + #tk.messagebox.showerror(title='Hi', message='No!! never') # return 'ok' #print(tk.messagebox.askquestion(title='Hi', message='hahahaha')) # return 'yes' , 'no' #print(tk.messagebox.askyesno(title='Hi', message='hahahaha')) # return True, False print(tk.messagebox.asktrycancel(title='Hi', message='hahahaha')) # return True, False