diff --git a/lessons/lesson09.ipynb b/lessons/lesson09.ipynb index 33c8959..0c138e3 100644 --- a/lessons/lesson09.ipynb +++ b/lessons/lesson09.ipynb @@ -329,29 +329,28 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "AaBbBbCcCcCcDdDdDdDd\n", - "Aa\n", - "BbBb\n", - "CcCcCc\n", - "DdDdDdDd\n" + "AaBbCcDdEeFfGg\n", + "HhIi\n", + "Jj\n", + "Kk\n" ] } ], "source": [ "%%bash\n", - "cat test_regex.txt" + "cat ../practice/test_regex.txt" ] }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 5, "metadata": { "scrolled": true }, @@ -360,81 +359,86 @@ "name": "stdout", "output_type": "stream", "text": [ - "AaBbBbCcCcCcDdDdDdDd\n", - "Aa\n" + "AaBbCcDdEeFfGg\n" ] } ], "source": [ "%%bash\n", - "egrep \"Aa\" test_regex.txt" + "egrep \"Aa\" ../practice/test_regex.txt" ] }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 15, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "CcCcCc\n" + "CcCcline\n" ] } ], "source": [ "%%bash\n", - "egrep \"^Cc\" test_regex.txt" + "egrep \"^Cc\" ../practice/test_regex.txt" ] }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 20, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Ccctwocc\n" + ] + } + ], "source": [ "%%bash\n", - "egrep \"Cc{3}\" test_regex.txt" + "egrep \"Cc{2}\" ../practice/test_regex.txt" ] }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 22, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "AaBbBbCcCcCcDdDdDdDd\n", - "CcCcCc\n" + "CcCcCcCcthreeCc\n" ] } ], "source": [ "%%bash\n", - "egrep \"(Cc){3}\" test_regex.txt" + "egrep \"(Cc){3}\" ../practice/test_regex.txt" ] }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 24, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "AaBbBbCcCcCcDdDdDdDd\n", - "CcCcCc\n", - "DdDdDdDd\n" + "AaBbCcDdEeFfGg\n", + "CcCcCcCcthreeCc\n" ] } ], "source": [ "%%bash\n", - "egrep \"([A-Z][a-z]){3}\" test_regex.txt" + "egrep \"([A-Z][a-z]){3}\" ../practice/test_regex.txt" ] }, { @@ -461,7 +465,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 25, "metadata": {}, "outputs": [], "source": [ @@ -502,18 +506,18 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 31, "metadata": {}, "outputs": [], "source": [ "# Example 1\n", "\n", - "x = 'Begin With Review And Friend'" + "x = 'Begin With Review And Friend. While this is a test.'" ] }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 32, "metadata": {}, "outputs": [ { @@ -522,7 +526,7 @@ "<_sre.SRE_Match object; span=(6, 10), match='With'>" ] }, - "execution_count": 17, + "execution_count": 32, "metadata": {}, "output_type": "execute_result" } @@ -533,7 +537,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 33, "metadata": {}, "outputs": [ { @@ -542,7 +546,7 @@ "'With'" ] }, - "execution_count": 18, + "execution_count": 33, "metadata": {}, "output_type": "execute_result" } @@ -553,7 +557,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 34, "metadata": {}, "outputs": [], "source": [ @@ -562,7 +566,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 35, "metadata": {}, "outputs": [ { @@ -571,7 +575,7 @@ "'With'" ] }, - "execution_count": 20, + "execution_count": 35, "metadata": {}, "output_type": "execute_result" } @@ -582,7 +586,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 36, "metadata": {}, "outputs": [], "source": [ @@ -591,7 +595,7 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 37, "metadata": { "scrolled": true }, @@ -602,7 +606,7 @@ "<_sre.SRE_Match object; span=(0, 5), match='Begin'>" ] }, - "execution_count": 22, + "execution_count": 37, "metadata": {}, "output_type": "execute_result" } @@ -613,7 +617,7 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 38, "metadata": {}, "outputs": [ { @@ -622,7 +626,7 @@ "<_sre.SRE_Match object; span=(0, 5), match='Begin'>" ] }, - "execution_count": 23, + "execution_count": 38, "metadata": {}, "output_type": "execute_result" } @@ -633,7 +637,7 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 40, "metadata": {}, "outputs": [], "source": [ @@ -642,29 +646,29 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 45, "metadata": {}, "outputs": [], "source": [ "# Example 2\n", "\n", - "line = \"3.8 Liters in 1 Gallon\"\n", + "line = \"3.8 Liters in 1 Gallon 4.45\"\n", "\n", - "searchObj = re.search(r'([.0-9]*) liters in ([.0-9]*) gallon', line, re.I)" + "searchObj = re.search(r'([.0-9]*) liters in ([.0-9]*) gallon ([.0-9]*)', line, re.I)" ] }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 46, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "('3.8', '1')" + "('3.8', '1', '4.45')" ] }, - "execution_count": 26, + "execution_count": 46, "metadata": {}, "output_type": "execute_result" } @@ -675,16 +679,16 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 47, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "'3.8 Liters in 1 Gallon'" + "'3.8 Liters in 1 Gallon 4.45'" ] }, - "execution_count": 27, + "execution_count": 47, "metadata": {}, "output_type": "execute_result" } @@ -695,24 +699,27 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 51, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "searchObj.group() : 3.8 Liters in 1 Gallon\n", + "searchObj.group() : 3.8 Liters in 1 Gallon 4.45\n", "searchObj.group(1) : 3.8\n", - "searchObj.group(2) : 1\n" + "searchObj.group(2) : 1\n", + "searchObj.group(3): 4.45\n" ] } ], "source": [ + "# 注意空3行\n", "if searchObj:\n", " print(\"searchObj.group() : \", searchObj.group())\n", " print(\"searchObj.group(1) : \", searchObj.group(1))\n", " print(\"searchObj.group(2) : \", searchObj.group(2))\n", + " print(\"searchObj.group(3): \", searchObj.group(3))\n", "else:\n", " print(\"Nothing found!!\")" ] @@ -734,18 +741,18 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 61, "metadata": {}, "outputs": [], "source": [ "# Example 3\n", "\n", - "phone = \"2004-959-559 # This is Phone Number\"" + "phone = \"2004-959-559 # This is Phone Number, # second phone number 152551232123\"" ] }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 72, "metadata": {}, "outputs": [ { @@ -754,7 +761,7 @@ "'2004-959-559 '" ] }, - "execution_count": 30, + "execution_count": 72, "metadata": {}, "output_type": "execute_result" } @@ -767,7 +774,7 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 60, "metadata": {}, "outputs": [ { @@ -776,7 +783,7 @@ "'2004-959-559'" ] }, - "execution_count": 31, + "execution_count": 60, "metadata": {}, "output_type": "execute_result" } @@ -787,16 +794,16 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 77, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "'2004959559'" + "'2004959559152551232123'" ] }, - "execution_count": 32, + "execution_count": 77, "metadata": {}, "output_type": "execute_result" } @@ -818,7 +825,7 @@ }, { "cell_type": "code", - "execution_count": 33, + "execution_count": 78, "metadata": {}, "outputs": [ { @@ -827,7 +834,7 @@ "re.compile(r'ab*', re.UNICODE)" ] }, - "execution_count": 33, + "execution_count": 78, "metadata": {}, "output_type": "execute_result" } @@ -835,13 +842,13 @@ "source": [ "# Example 4\n", "\n", - "p = re.compile('ab*')\n", + "p = re.compile('ab*') \n", "p" ] }, { "cell_type": "code", - "execution_count": 34, + "execution_count": 79, "metadata": {}, "outputs": [ { @@ -850,7 +857,7 @@ "<_sre.SRE_Match object; span=(2, 4), match='ab'>" ] }, - "execution_count": 34, + "execution_count": 79, "metadata": {}, "output_type": "execute_result" } @@ -862,7 +869,7 @@ }, { "cell_type": "code", - "execution_count": 35, + "execution_count": 80, "metadata": { "scrolled": true }, @@ -873,7 +880,7 @@ "'ab'" ] }, - "execution_count": 35, + "execution_count": 80, "metadata": {}, "output_type": "execute_result" } @@ -884,7 +891,7 @@ }, { "cell_type": "code", - "execution_count": 36, + "execution_count": 81, "metadata": { "scrolled": true }, @@ -895,7 +902,7 @@ "(2, 4)" ] }, - "execution_count": 36, + "execution_count": 81, "metadata": {}, "output_type": "execute_result" } @@ -906,7 +913,7 @@ }, { "cell_type": "code", - "execution_count": 37, + "execution_count": 82, "metadata": {}, "outputs": [ { @@ -915,7 +922,7 @@ "2" ] }, - "execution_count": 37, + "execution_count": 82, "metadata": {}, "output_type": "execute_result" } @@ -926,7 +933,7 @@ }, { "cell_type": "code", - "execution_count": 38, + "execution_count": 83, "metadata": {}, "outputs": [ { @@ -935,7 +942,7 @@ "4" ] }, - "execution_count": 38, + "execution_count": 83, "metadata": {}, "output_type": "execute_result" } @@ -946,19 +953,19 @@ }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 90, "metadata": {}, "outputs": [], "source": [ "# Example 5\n", "\n", "q = re.compile('[a-z]+')\n", - "n = q.match('tempo')" + "n = q.match('tempodddFD')" ] }, { "cell_type": "code", - "execution_count": 40, + "execution_count": 91, "metadata": {}, "outputs": [ { @@ -967,7 +974,7 @@ "re.compile(r'[a-z]+', re.UNICODE)" ] }, - "execution_count": 40, + "execution_count": 91, "metadata": {}, "output_type": "execute_result" } @@ -978,7 +985,7 @@ }, { "cell_type": "code", - "execution_count": 41, + "execution_count": 92, "metadata": { "scrolled": true }, @@ -986,10 +993,10 @@ { "data": { "text/plain": [ - "<_sre.SRE_Match object; span=(0, 5), match='tempo'>" + "<_sre.SRE_Match object; span=(0, 8), match='tempoddd'>" ] }, - "execution_count": 41, + "execution_count": 92, "metadata": {}, "output_type": "execute_result" } @@ -1000,16 +1007,16 @@ }, { "cell_type": "code", - "execution_count": 42, + "execution_count": 93, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "'tempo'" + "'tempoddd'" ] }, - "execution_count": 42, + "execution_count": 93, "metadata": {}, "output_type": "execute_result" } @@ -1020,7 +1027,7 @@ }, { "cell_type": "code", - "execution_count": 43, + "execution_count": 94, "metadata": { "scrolled": true }, @@ -1028,10 +1035,10 @@ { "data": { "text/plain": [ - "(0, 5)" + "(0, 8)" ] }, - "execution_count": 43, + "execution_count": 94, "metadata": {}, "output_type": "execute_result" } @@ -1051,16 +1058,34 @@ }, { "cell_type": "code", - "execution_count": 44, + "execution_count": 97, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "['e', 'r', 'e', 's', 't', 'r', 'i', 'n', 'g']" + "['e',\n", + " 'r',\n", + " 'e',\n", + " 's',\n", + " 'A',\n", + " 't',\n", + " 'r',\n", + " 'i',\n", + " 'n',\n", + " 'g',\n", + " 'a',\n", + " 'n',\n", + " 'd',\n", + " 'a',\n", + " 't',\n", + " 'r',\n", + " 'i',\n", + " 'n',\n", + " 'g']" ] }, - "execution_count": 44, + "execution_count": 97, "metadata": {}, "output_type": "execute_result" } @@ -1068,31 +1093,31 @@ "source": [ "# Example 6\n", "\n", - "regex = re.compile('[a-z]')\n", - "string = 'Here Is A String'\n", + "regex = re.compile('[a-zA]')\n", + "string = 'Here Is A String and a String'\n", "letters = regex.findall(string)\n", "letters" ] }, { "cell_type": "code", - "execution_count": 45, + "execution_count": 103, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "['Here', 'Is', 'A', 'String']" + "['Here', 'Is', 'A', 'String', 'Sa', 'S']" ] }, - "execution_count": 45, + "execution_count": 103, "metadata": {}, "output_type": "execute_result" } ], "source": [ "regex = re.compile(r'[A-Z][a-z]*')\n", - "string = 'Here Is A String'\n", + "string = 'Here Is A String a Sa aS'\n", "words = regex.findall(string)\n", "words" ] @@ -1305,7 +1330,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.4" + "version": "3.6.5" } }, "nbformat": 4, diff --git a/lessons/lesson10.ipynb b/lessons/lesson10.ipynb index 4fb20f6..77aeb02 100644 --- a/lessons/lesson10.ipynb +++ b/lessons/lesson10.ipynb @@ -32,7 +32,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -58,46 +58,46 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "array([1, 2, 3, 4])" + "array([1, 2, 3, 4, 5])" ] }, - "execution_count": 2, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# a vector: the argument to the array function is a Python list\n", - "v = np.array([1,2,3,4])\n", + "v = np.array([1,2,3,4,5])\n", "v" ] }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "array([[1, 2],\n", - " [3, 4]])" + "array([[1, 2, 4],\n", + " [3, 4, 1]])" ] }, - "execution_count": 3, + "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# a matrix: the argument to the array function is a nested Python list\n", - "M = np.array([[1, 2], [3, 4]])\n", + "M = np.array([[1, 2, 4], [3, 4, 1]])\n", "M" ] }, @@ -110,7 +110,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 14, "metadata": {}, "outputs": [ { @@ -119,7 +119,7 @@ "(numpy.ndarray, numpy.ndarray)" ] }, - "execution_count": 4, + "execution_count": 14, "metadata": {}, "output_type": "execute_result" } @@ -137,16 +137,18 @@ }, { "cell_type": "code", - "execution_count": 5, - "metadata": {}, + "execution_count": 7, + "metadata": { + "scrolled": true + }, "outputs": [ { "data": { "text/plain": [ - "(4,)" + "(5,)" ] }, - "execution_count": 5, + "execution_count": 7, "metadata": {}, "output_type": "execute_result" } @@ -157,16 +159,16 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "(2, 2)" + "(2, 3)" ] }, - "execution_count": 6, + "execution_count": 15, "metadata": {}, "output_type": "execute_result" } @@ -184,16 +186,16 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "4" + "6" ] }, - "execution_count": 7, + "execution_count": 17, "metadata": {}, "output_type": "execute_result" } @@ -211,16 +213,16 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "(2, 2)" + "(2, 3)" ] }, - "execution_count": 8, + "execution_count": 18, "metadata": {}, "output_type": "execute_result" } @@ -231,16 +233,16 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "4" + "6" ] }, - "execution_count": 9, + "execution_count": 19, "metadata": {}, "output_type": "execute_result" } @@ -267,7 +269,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 20, "metadata": {}, "outputs": [ { @@ -276,7 +278,7 @@ "dtype('int64')" ] }, - "execution_count": 10, + "execution_count": 20, "metadata": {}, "output_type": "execute_result" } @@ -296,16 +298,29 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 21, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "array([[1, 2, 4],\n", + " [3, 4, 1]])" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "#M[0,0] = 'hello'" + "#M[0,0] = 'hello'\n", + "M" ] }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 22, "metadata": {}, "outputs": [], "source": [ @@ -314,17 +329,17 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 23, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "array([[5, 2],\n", - " [3, 4]])" + "array([[5, 2, 4],\n", + " [3, 4, 1]])" ] }, - "execution_count": 13, + "execution_count": 23, "metadata": {}, "output_type": "execute_result" } @@ -344,7 +359,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 24, "metadata": {}, "outputs": [ { @@ -354,7 +369,7 @@ " [3.+0.j, 4.+0.j]])" ] }, - "execution_count": 14, + "execution_count": 24, "metadata": {}, "output_type": "execute_result" } @@ -384,31 +399,29 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 26, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "array([-5.00000000e-01, -4.00000000e-01, -3.00000000e-01, -2.00000000e-01,\n", - " -1.00000000e-01, -1.11022302e-16, 1.00000000e-01, 2.00000000e-01,\n", - " 3.00000000e-01, 4.00000000e-01])" + "array([-0.5, -0.2, 0.1, 0.4])" ] }, - "execution_count": 15, + "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# create a range (the end value is not included)\n", - "x = np.arange(-0.5, 0.5, 0.1) # arguments: start, stop, step\n", + "x = np.arange(-0.5, 0.5, 0.3) # arguments: start, stop, step\n", "x" ] }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 27, "metadata": {}, "outputs": [ { @@ -417,43 +430,40 @@ "dtype('float64')" ] }, - "execution_count": 16, + "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ + "# array.dtype 展示数组的类型\n", "x.dtype" ] }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 32, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "array([ 0. , 0.41666667, 0.83333333, 1.25 , 1.66666667,\n", - " 2.08333333, 2.5 , 2.91666667, 3.33333333, 3.75 ,\n", - " 4.16666667, 4.58333333, 5. , 5.41666667, 5.83333333,\n", - " 6.25 , 6.66666667, 7.08333333, 7.5 , 7.91666667,\n", - " 8.33333333, 8.75 , 9.16666667, 9.58333333, 10. ])" + "array([ 0. , 3.33333333, 6.66666667, 10. ])" ] }, - "execution_count": 17, + "execution_count": 32, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# using linspace, both end points ARE included\n", - "np.linspace(0, 10, 25) # arguments: start, stop, N" + "np.linspace(0, 10, 4) # arguments: start, stop, N" ] }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 33, "metadata": {}, "outputs": [], "source": [ @@ -463,7 +473,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 34, "metadata": {}, "outputs": [ { @@ -476,7 +486,7 @@ " [4, 4, 4, 4, 4]])" ] }, - "execution_count": 19, + "execution_count": 34, "metadata": {}, "output_type": "execute_result" } @@ -487,7 +497,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 35, "metadata": {}, "outputs": [ { @@ -500,7 +510,7 @@ " [0, 1, 2, 3, 4]])" ] }, - "execution_count": 20, + "execution_count": 35, "metadata": {}, "output_type": "execute_result" } @@ -511,45 +521,46 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 50, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "array([[0.35680677, 0.02840877, 0.72867736, 0.16159907, 0.44469075],\n", - " [0.24009966, 0.81989462, 0.8592401 , 0.3993646 , 0.30377854],\n", - " [0.22722364, 0.19765586, 0.27481477, 0.68241593, 0.18169057],\n", - " [0.02432646, 0.63200567, 0.21140597, 0.94898166, 0.86289505],\n", - " [0.28856095, 0.33198879, 0.94004425, 0.17110496, 0.55798523]])" + "array([[0.46594118, 0.47680214, 0.85852029, 0.8308781 ],\n", + " [0.24435183, 0.25823839, 0.14809209, 0.21989137],\n", + " [0.85554991, 0.36600804, 0.79901964, 0.58203401],\n", + " [0.61796468, 0.97860962, 0.66670709, 0.74754557],\n", + " [0.14556563, 0.2971433 , 0.41746786, 0.94157509]])" ] }, - "execution_count": 21, + "execution_count": 50, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# uniform random numbers in interval [0,1]\n", - "np.random.rand(5,5)" + "# 5行4列随机数\n", + "np.random.rand(5,4)" ] }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 61, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "array([[-1.39008688, 1.99102486, 0.76260535, 1.35160466, -1.48029724],\n", - " [-0.66974064, 1.37869926, -2.51814177, 0.65754097, -0.59623496],\n", - " [-1.46103157, 0.78296596, 2.85503094, -0.44920096, 0.98951867],\n", - " [-2.65255117, 1.40335448, -0.65150212, 0.11626776, -0.01676508],\n", - " [ 1.0598403 , 1.01645399, -1.20170219, -1.11820802, 0.55218374]])" + "array([[-2.50280321, -0.2888322 , -1.03797516, 0.94140558, -2.66274976],\n", + " [-1.11209581, -1.38372215, -1.29498591, 0.29830935, -0.49413356],\n", + " [-0.61403121, 0.57077411, 1.16162382, -1.13767139, -1.58022421],\n", + " [-0.80879605, 0.34231568, 0.9149333 , -0.43930554, 0.33289006],\n", + " [-0.06234454, -0.19224235, 2.45734432, 0.87140496, 1.08397648]])" ] }, - "execution_count": 22, + "execution_count": 61, "metadata": {}, "output_type": "execute_result" } @@ -561,7 +572,7 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 62, "metadata": {}, "outputs": [ { @@ -572,13 +583,14 @@ " [0, 0, 3]])" ] }, - "execution_count": 23, + "execution_count": 62, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# diagonal matrix\n", + "# 对角矩阵\n", "np.diag([1,2,3])" ] }, @@ -602,12 +614,13 @@ ], "source": [ "# zeros\n", + "# 0矩阵\n", "np.zeros((3,3))" ] }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 63, "metadata": {}, "outputs": [ { @@ -618,7 +631,7 @@ " [1., 1., 1.]])" ] }, - "execution_count": 25, + "execution_count": 63, "metadata": {}, "output_type": "execute_result" } @@ -630,7 +643,7 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 64, "metadata": {}, "outputs": [ { @@ -641,7 +654,7 @@ " [1, 1, 1]])" ] }, - "execution_count": 26, + "execution_count": 64, "metadata": {}, "output_type": "execute_result" } @@ -662,28 +675,69 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 70, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "1" + "array([1, 2, 3, 4, 5])" ] }, - "execution_count": 27, + "execution_count": 70, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# v is a vector, and has only one dimension, taking one index\n", - "v[0]" + "v" ] }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 69, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3" + ] + }, + "execution_count": 69, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "v[2]" + ] + }, + { + "cell_type": "code", + "execution_count": 72, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([[5, 2, 4],\n", + " [3, 4, 1]])" + ] + }, + "execution_count": 72, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "M" + ] + }, + { + "cell_type": "code", + "execution_count": 73, "metadata": {}, "outputs": [ { @@ -692,7 +746,7 @@ "4" ] }, - "execution_count": 28, + "execution_count": 73, "metadata": {}, "output_type": "execute_result" } @@ -704,23 +758,24 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 76, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "array([3, 4])" + "array([5, 2, 4])" ] }, - "execution_count": 29, + "execution_count": 76, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "# If we omit an index of a multidimensional array it returns the whole row (or, in general, a N-1 dimensional array)\n", - "M[1]" + "# If we omit an index of a multidimensional array it returns \n", + "# the whole row (or, in general, a N-1 dimensional array)\n", + "M[0]" ] }, { @@ -732,42 +787,42 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 79, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "array([3, 4])" + "array([5, 2, 4])" ] }, - "execution_count": 30, + "execution_count": 79, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "M[1,:] # row 1" + "M[0,:] # row 1" ] }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 80, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "array([2, 4])" + "array([4, 1])" ] }, - "execution_count": 31, + "execution_count": 80, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "M[:,1] # column 1" + "M[:,2] # column 1" ] }, { @@ -779,17 +834,17 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 81, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "array([[-1, 2],\n", - " [ 3, 4]])" + "array([[-1, 2, 4],\n", + " [ 3, 4, 1]])" ] }, - "execution_count": 32, + "execution_count": 81, "metadata": {}, "output_type": "execute_result" } @@ -801,28 +856,30 @@ }, { "cell_type": "code", - "execution_count": 33, + "execution_count": 83, "metadata": {}, "outputs": [], "source": [ "# also works for rows and columns\n", + "# 第一行变为0\n", "M[0,:] = 0\n", + "# 第2列变为-2\n", "M[:,1] = -2" ] }, { "cell_type": "code", - "execution_count": 34, + "execution_count": 85, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "array([[ 0, -2],\n", - " [ 3, -2]])" + "array([[ 0, -2, 0],\n", + " [ 3, -2, 1]])" ] }, - "execution_count": 34, + "execution_count": 85, "metadata": {}, "output_type": "execute_result" } @@ -847,28 +904,28 @@ }, { "cell_type": "code", - "execution_count": 35, + "execution_count": 88, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "array([1, 2, 3, 4, 5])" + "array([1, 2, 3, 4, 5, 6])" ] }, - "execution_count": 35, + "execution_count": 88, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "A = np.array([1,2,3,4,5])\n", + "A = np.array([1,2,3,4,5,6])\n", "A" ] }, { "cell_type": "code", - "execution_count": 36, + "execution_count": 89, "metadata": {}, "outputs": [ { @@ -877,7 +934,7 @@ "array([2, 3])" ] }, - "execution_count": 36, + "execution_count": 89, "metadata": {}, "output_type": "execute_result" } @@ -890,21 +947,22 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Array slices are *mutable*: if they are assigned a new value the original array from which the slice was extracted is modified:" + "Array slices are *mutable*: if they are assigned a new value the original array from which the slice was extracted is modified:\n", + "- 可变" ] }, { "cell_type": "code", - "execution_count": 37, + "execution_count": 90, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "array([ 1, -2, -3, 4, 5])" + "array([ 1, -2, -3, 4, 5, 6])" ] }, - "execution_count": 37, + "execution_count": 90, "metadata": {}, "output_type": "execute_result" } @@ -923,16 +981,16 @@ }, { "cell_type": "code", - "execution_count": 38, + "execution_count": 91, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "array([ 1, -2, -3, 4, 5])" + "array([ 1, -2, -3, 4, 5, 6])" ] }, - "execution_count": 38, + "execution_count": 91, "metadata": {}, "output_type": "execute_result" } @@ -943,27 +1001,29 @@ }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 94, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "array([ 1, -3, 5])" + "array([1, 5])" ] }, - "execution_count": 39, + "execution_count": 94, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "A[::2] # step is 2, lower and upper defaults to the beginning and end of the array" + "# step is 2, lower and upper defaults to the beginning and end of the array\n", + "# 跨两步\n", + "A[::2] " ] }, { "cell_type": "code", - "execution_count": 40, + "execution_count": 95, "metadata": {}, "outputs": [ { @@ -972,7 +1032,7 @@ "array([ 1, -2, -3])" ] }, - "execution_count": 40, + "execution_count": 95, "metadata": {}, "output_type": "execute_result" } @@ -983,16 +1043,16 @@ }, { "cell_type": "code", - "execution_count": 41, + "execution_count": 96, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "array([4, 5])" + "array([4, 5, 6])" ] }, - "execution_count": 41, + "execution_count": 96, "metadata": {}, "output_type": "execute_result" } @@ -1010,7 +1070,7 @@ }, { "cell_type": "code", - "execution_count": 42, + "execution_count": 97, "metadata": {}, "outputs": [], "source": [ @@ -1019,7 +1079,7 @@ }, { "cell_type": "code", - "execution_count": 43, + "execution_count": 98, "metadata": {}, "outputs": [ { @@ -1028,7 +1088,7 @@ "5" ] }, - "execution_count": 43, + "execution_count": 98, "metadata": {}, "output_type": "execute_result" } @@ -1039,22 +1099,22 @@ }, { "cell_type": "code", - "execution_count": 44, + "execution_count": 101, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "array([3, 4, 5])" + "array([4, 5])" ] }, - "execution_count": 44, + "execution_count": 101, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "A[-3:] # the last three elements" + "A[-2:] # the last three elements" ] }, { @@ -3035,21 +3095,21 @@ "metadata": { "anaconda-cloud": {}, "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 2", "language": "python", - "name": "python3" + "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", - "version": 3 + "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.4" + "version": "3.6.5" } }, "nbformat": 4, diff --git a/nemcache.sqlite b/nemcache.sqlite new file mode 100644 index 0000000..caadd65 Binary files /dev/null and b/nemcache.sqlite differ diff --git a/practice/for.sh b/practice/for.sh new file mode 100755 index 0000000..f4a6eb9 --- /dev/null +++ b/practice/for.sh @@ -0,0 +1,13 @@ +######################################################################### +# File Name: for.sh +# Author: Linking +# mail: w.linkings@gmail.com +# Created Time: 2018年06月22日 星期五 18时12分11秒 +######################################################################### +#!/bin/bash + + +for i in {1..3} +do + echo $i +done diff --git a/practice/if.sh b/practice/if.sh new file mode 100644 index 0000000..81f258a --- /dev/null +++ b/practice/if.sh @@ -0,0 +1,14 @@ +######################################################################### +# File Name: if.sh +# Author: Linking +# mail: w.linkings@gmail.com +# Created Time: 2018年06月22日 星期五 18时20分22秒 +######################################################################### +#!/bin/bash + + +if [ -d "test" ]; then + echo "Dir exists" +else + mkdir test +fi diff --git a/practice/test.md b/practice/test.md new file mode 100755 index 0000000..e7354ca --- /dev/null +++ b/practice/test.md @@ -0,0 +1,16 @@ +this is a car > msg. + +w + + + + +:w + + +this is a line append. + + + +:w +sdfa diff --git a/practice/test.txt b/practice/test.txt new file mode 100644 index 0000000..901e034 --- /dev/null +++ b/practice/test.txt @@ -0,0 +1,11 @@ +this is a text file.Which use to test cut command.aaaaaaa +this is a text file.Which use to test cut command. +this is a text file.Which use to test cut command. +this is a text file.Which use to test cut command. +this is a text file.Which use to test cut command. +this is a text file.Which use to test cut command. +this is a text file.Which use to test cut command. +this is a text file.Which use to test cut command. +this is a text file.Which use to test cut command. +this is a text file.Which use to test cut command. +this is a text file.Which use to test cut command. diff --git a/practice/test_regex.txt b/practice/test_regex.txt new file mode 100644 index 0000000..8422ee6 --- /dev/null +++ b/practice/test_regex.txt @@ -0,0 +1,11 @@ +AaBbCcDdEeFfGg +HhIi +Jj +Kk +CcCcline + +Ccctwocc + + +CcCcCcCcthreeCc +