Browse Source

Fix some python minor errors

pull/1/MERGE
bushuhui 5 years ago
parent
commit
23c96ac8fe
7 changed files with 154 additions and 100 deletions
  1. +17
    -20
      0_python/1_Basics.ipynb
  2. +9
    -9
      0_python/2_Print_Statement.ipynb
  3. +105
    -64
      0_python/3_Data_Structure_1.ipynb
  4. +1
    -1
      0_python/4_Data_Structure_2.ipynb
  5. +19
    -1
      1_numpy_matplotlib_scipy_sympy/ipython_notebook.ipynb
  6. +3
    -3
      1_numpy_matplotlib_scipy_sympy/matplotlib_ani.ipynb
  7. +0
    -2
      2_knn/knn_classification.ipynb

+ 17
- 20
0_python/1_Basics.ipynb View File

@@ -644,9 +644,9 @@
} }
], ],
"source": [ "source": [
"print int('010',8)\n",
"print int('0xaa',16)\n",
"print int('1010',2)"
"print(int('010',8))\n",
"print(int('0xaa',16))\n",
"print(int('1010',2))"
] ]
}, },
{ {
@@ -864,10 +864,7 @@
} }
], ],
"source": [ "source": [
"print(1<2)\n",
"#print(cmp(1,2))\n",
"#print(cmp(2,1))\n",
"#print(cmp(2,2))"
"print(1<2)"
] ]
}, },
{ {
@@ -892,8 +889,8 @@
} }
], ],
"source": [ "source": [
"print pow(3,3)\n",
"print pow(3,3,5)"
"print(pow(3,3))\n",
"print(pow(3,3,5))"
] ]
}, },
{ {
@@ -905,23 +902,23 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 22,
"execution_count": 1,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"range(0, 3)\n",
"range(2, 9)\n",
"range(2, 27, 8)\n"
"[0, 1, 2]\n",
"[2, 3, 4, 5, 6, 7, 8]\n",
"[2, 10, 18, 26]\n"
] ]
} }
], ],
"source": [ "source": [
"print(range(3))\n",
"print(range(2,9))\n",
"print(range(2,27,8))"
"print(list(range(3)))\n",
"print(list(range(2,9)))\n",
"print(list(range(2,27,8)))"
] ]
}, },
{ {
@@ -940,14 +937,14 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 23,
"execution_count": 2,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"Type something here and it will be stored in variable abc \tHello world!\n"
"Type something here and it will be stored in variable abc \taa\n"
] ]
} }
], ],
@@ -957,7 +954,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 24,
"execution_count": 3,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -966,7 +963,7 @@
"str" "str"
] ]
}, },
"execution_count": 24,
"execution_count": 3,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }


+ 9
- 9
0_python/2_Print_Statement.ipynb View File

@@ -71,7 +71,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 3,
"execution_count": 1,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -99,7 +99,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 1,
"execution_count": 2,
"metadata": { "metadata": {
"scrolled": true "scrolled": true
}, },
@@ -130,7 +130,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 2,
"execution_count": 3,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -154,7 +154,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 6,
"execution_count": 4,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -187,7 +187,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 3,
"execution_count": 6,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -219,7 +219,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 4,
"execution_count": 7,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -250,7 +250,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 9,
"execution_count": 8,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -267,7 +267,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 5,
"execution_count": 9,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -308,7 +308,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 12,
"execution_count": 10,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {


+ 105
- 64
0_python/3_Data_Structure_1.ipynb View File

@@ -72,7 +72,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 4,
"execution_count": 3,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -104,7 +104,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 5,
"execution_count": 4,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -113,7 +113,7 @@
"'apple'" "'apple'"
] ]
}, },
"execution_count": 5,
"execution_count": 4,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@@ -131,16 +131,16 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 6,
"execution_count": 5,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"'orange'"
"'peach'"
] ]
}, },
"execution_count": 6,
"execution_count": 5,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@@ -158,7 +158,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 5,
"execution_count": 6,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@@ -174,7 +174,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 6,
"execution_count": 8,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -192,7 +192,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 7,
"execution_count": 9,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -201,7 +201,7 @@
"'orange'" "'orange'"
] ]
}, },
"execution_count": 7,
"execution_count": 9,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@@ -222,7 +222,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 12,
"execution_count": 10,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -247,9 +247,20 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null,
"execution_count": 12,
"metadata": {}, "metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"'apple'"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [ "source": [
"z1[0]" "z1[0]"
] ]
@@ -263,9 +274,20 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null,
"execution_count": 13,
"metadata": {}, "metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"'apple'"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [ "source": [
"z[0][0]" "z[0][0]"
] ]
@@ -295,25 +317,24 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 10,
"execution_count": 15,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"data": {
"text/plain": [
"[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
"name": "stdout",
"output_type": "stream",
"text": [
"[0, 1, 2, 3]\n",
"[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n",
"[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n"
]
} }
], ],
"source": [ "source": [
"num = [0,1,2,3,4,5,6,7,8,9]\n", "num = [0,1,2,3,4,5,6,7,8,9]\n",
"num[0:4]\n",
"num[0:]\n",
"num[:]"
"print(num[0:4])\n",
"print(num[0:])\n",
"print(num[:])"
] ]
}, },
{ {
@@ -344,7 +365,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 11,
"execution_count": 17,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -353,7 +374,7 @@
"[0, 3, 6]" "[0, 3, 6]"
] ]
}, },
"execution_count": 11,
"execution_count": 17,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@@ -378,7 +399,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 12,
"execution_count": 18,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -387,7 +408,7 @@
"10" "10"
] ]
}, },
"execution_count": 12,
"execution_count": 18,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@@ -405,7 +426,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 13,
"execution_count": 19,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -414,7 +435,7 @@
"0" "0"
] ]
}, },
"execution_count": 13,
"execution_count": 19,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@@ -425,7 +446,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 14,
"execution_count": 20,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -434,7 +455,7 @@
"9" "9"
] ]
}, },
"execution_count": 14,
"execution_count": 20,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@@ -452,7 +473,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 15,
"execution_count": 21,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -461,7 +482,7 @@
"[1, 2, 3, 5, 4, 7]" "[1, 2, 3, 5, 4, 7]"
] ]
}, },
"execution_count": 15,
"execution_count": 21,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@@ -479,7 +500,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 16,
"execution_count": 22,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@@ -495,7 +516,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 18,
"execution_count": 23,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -504,7 +525,7 @@
"False" "False"
] ]
}, },
"execution_count": 18,
"execution_count": 23,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@@ -515,7 +536,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 17,
"execution_count": 24,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -524,7 +545,7 @@
"True" "True"
] ]
}, },
"execution_count": 17,
"execution_count": 24,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@@ -535,7 +556,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 19,
"execution_count": 26,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -544,7 +565,27 @@
"False" "False"
] ]
}, },
"execution_count": 19,
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"'fire' in names"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 25,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@@ -562,7 +603,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 20,
"execution_count": 27,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@@ -571,7 +612,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 21,
"execution_count": 28,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -597,7 +638,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 22,
"execution_count": 29,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@@ -606,7 +647,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 23,
"execution_count": 30,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -639,7 +680,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 22,
"execution_count": 31,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -696,7 +737,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 25,
"execution_count": 33,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@@ -705,7 +746,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 26,
"execution_count": 34,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -730,7 +771,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 27,
"execution_count": 35,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -739,7 +780,7 @@
"3" "3"
] ]
}, },
"execution_count": 27,
"execution_count": 35,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@@ -757,7 +798,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 28,
"execution_count": 36,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@@ -766,7 +807,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 29,
"execution_count": 37,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -791,7 +832,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 30,
"execution_count": 38,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -816,7 +857,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 31,
"execution_count": 39,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -825,7 +866,7 @@
"0" "0"
] ]
}, },
"execution_count": 31,
"execution_count": 39,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@@ -836,7 +877,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 32,
"execution_count": 40,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -846,7 +887,7 @@
"traceback": [ "traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-32-344da5bcf759>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mlst\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mindex\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m999\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;32m<ipython-input-40-344da5bcf759>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mlst\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mindex\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m999\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;31mValueError\u001b[0m: 999 is not in list" "\u001b[0;31mValueError\u001b[0m: 999 is not in list"
] ]
} }
@@ -864,7 +905,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 33,
"execution_count": 41,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -889,7 +930,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 34,
"execution_count": 42,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -914,7 +955,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 36,
"execution_count": 44,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -923,7 +964,7 @@
"[1, 1, 4, 8, 7, 'Python', 1, [5, 4, 2, 8], 5, 4]" "[1, 1, 4, 8, 7, 'Python', 1, [5, 4, 2, 8], 5, 4]"
] ]
}, },
"execution_count": 36,
"execution_count": 44,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }


+ 1
- 1
0_python/4_Data_Structure_2.ipynb View File

@@ -52,7 +52,7 @@
} }
], ],
"source": [ "source": [
"print(String0 , type(String0))\n",
"print(String0, type(String0))\n",
"print(String1, type(String1))\n", "print(String1, type(String1))\n",
"print(String2, type(String2))" "print(String2, type(String2))"
] ]


+ 19
- 1
1_numpy_matplotlib_scipy_sympy/ipython_notebook.ipynb View File

@@ -314,7 +314,25 @@
] ]
} }
], ],
"metadata": {},
"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.2"
}
},
"nbformat": 4, "nbformat": 4,
"nbformat_minor": 2 "nbformat_minor": 2
} }

+ 3
- 3
1_numpy_matplotlib_scipy_sympy/matplotlib_ani.ipynb
File diff suppressed because it is too large
View File


+ 0
- 2
2_knn/knn_classification.ipynb View File

@@ -7,8 +7,6 @@
"# kNN Classification\n", "# kNN Classification\n",
"\n", "\n",
"\n", "\n",
"kNN最邻近规则,主要应用领域是对未知事物的识别,即判断未知事物属于哪一类,判断思想是,基于欧几里得定理,判断未知事物的特征和哪一类已知事物的的特征最接近;\n",
"\n",
"K最近邻(k-Nearest Neighbor,kNN)分类算法,是一个理论上比较成熟的方法,也是最简单的机器学习算法之一。该方法的思路是:如果一个样本在特征空间中的k个最相似(即特征空间中最邻近)的样本中的大多数属于某一个类别,则该样本也属于这个类别。KNN算法中,所选择的邻居都是已经正确分类的对象。该方法在定类决策上只依据最邻近的一个或者几个样本的类别来决定待分样本所属的类别。 KNN方法虽然从原理上也依赖于极限定理,但在类别决策时,只与极少量的相邻样本有关。由于KNN方法主要靠周围有限的邻近的样本,而不是靠判别类域的方法来确定所属类别的,因此对于类域的交叉或重叠较多的待分样本集来说,KNN方法较其他方法更为适合。\n", "K最近邻(k-Nearest Neighbor,kNN)分类算法,是一个理论上比较成熟的方法,也是最简单的机器学习算法之一。该方法的思路是:如果一个样本在特征空间中的k个最相似(即特征空间中最邻近)的样本中的大多数属于某一个类别,则该样本也属于这个类别。KNN算法中,所选择的邻居都是已经正确分类的对象。该方法在定类决策上只依据最邻近的一个或者几个样本的类别来决定待分样本所属的类别。 KNN方法虽然从原理上也依赖于极限定理,但在类别决策时,只与极少量的相邻样本有关。由于KNN方法主要靠周围有限的邻近的样本,而不是靠判别类域的方法来确定所属类别的,因此对于类域的交叉或重叠较多的待分样本集来说,KNN方法较其他方法更为适合。\n",
"\n", "\n",
"kNN算法不仅可以用于分类,还可以用于回归。通过找出一个样本的k个最近邻居,将这些邻居的属性的平均值赋给该样本,就可以得到该样本的属性。更有用的方法是将不同距离的邻居对该样本产生的影响给予不同的权值(weight),如权值与距离成正比(组合函数)。\n", "kNN算法不仅可以用于分类,还可以用于回归。通过找出一个样本的k个最近邻居,将这些邻居的属性的平均值赋给该样本,就可以得到该样本的属性。更有用的方法是将不同距离的邻居对该样本产生的影响给予不同的权值(weight),如权值与距离成正比(组合函数)。\n",


Loading…
Cancel
Save