diff --git a/D2_of_3Day_DoneWithPython.md b/D2_of_3Day_DoneWithPython.md index a527cd9..bcff5f5 100644 --- a/D2_of_3Day_DoneWithPython.md +++ b/D2_of_3Day_DoneWithPython.md @@ -1,9 +1,6 @@ - - - # 《三天搞定Python基础概念之第二天》 Day 2 -### Day2,即第二篇主要是讲一些偏计算的Library的使用,也就是numpy,scipy,sympy和matplotlib。 +### Day2,即第二篇主要是讲一些偏计算的Library的使用,也就是numpy, scipy, sympy和matplotlib。 ``` 前言: @@ -24,7 +21,7 @@ ```python ``` -## 大纲( Outline) +## 大纲( Outline) * 第1天:Python和科学编程介绍。 Python中的基础知识:  - 数据类型  @@ -32,7 +29,7 @@ - 功能  - I/O文件 -* 第2天:用Numpy,Scipy,Matplotlib和其他模块进行计算。 用Python解决一些数学问题。 +* 第2天:用Numpy, Scipy, Matplotlib和其他模块进行计算。 用Python解决一些数学问题。 * 第3天:时间序列:用Pandas进行统计和实际数据分析。 随机和蒙特卡罗。 @@ -113,15 +110,16 @@ from scipy.stats import norm ```python import timeit -def funl (x, y):      - return x**2 + y**3 -t_start  =  timeit.default_timer() -z =  funl(109.2, 367.1) -t_end  =   timeit.default_timer() +def funl(x, y):      + return x**2 + y**3 -cost  =  t_end -t_start -print ( 'Time cost of funl is  %f' %cost) +t_start = timeit.default_timer() +z = funl(109.2, 367.1) +t_end = timeit.default_timer() + +cost = t_end - t_start +print('Time cost of funl is %f' % cost) ``` ------------------------------以下为英文原文------------------------------------- @@ -130,13 +128,16 @@ print ( 'Time cost of funl is  %f' %cost) ```python import timeit -def  funl (x, y):      -return x**2 + y**3 -t_start  =  timeit.default_timer() -z =  funl(109.2, 367.1) -t_end  =   timeit.default_timer() -cost  =  t_end -t_start -print ( 'Time cost of funl is  %f' %cost) + +def funl(x, y):      + return x**2 + y**3 + +t_start = timeit.default_timer() +z = funl(109.2, 367.1) +t_end = timeit.default_timer() + +cost = t_end - t_start +print('Time cost of funl is %f' % cost) ``` @@ -151,14 +152,14 @@ print ( 'Time cost of funl is  %f' %cost) ## 我们会遇到的模块 * NumPy:多维数组的有效操作。 高效的数学函数。 -* Matplotlib:可视化:2D和(最近)3D图 +* Matplotlib:可视化:2D和(最近)3D图 * SciPy:大型库实现各种数值算法,例如:            - 线性和非线性方程的解 - 优化 - 数值整合 -* Sympy:符号计算(解析的 Analytical) -* Pandas:统计与数据分析(明天) +* Sympy:符号计算(解析的 Analytical) +* Pandas:统计与数据分析(明天) ------------------------------以下为英文原文------------------------------------- @@ -187,8 +188,8 @@ print ( 'Time cost of funl is  %f' %cost) ## ndarray类型 -* NumPy提供了一种新的数据类型:ndarray(n维数组)。 - - 与元组和列表不同,数组只能存储相同类型的对象(例如只有floats或只有ints)  +* NumPy提供了一种新的数据类型:ndarray(n维数组)。 + - 与元组和列表不同,数组只能存储相同类型的对象(例如只有floats或只有ints)  - 这使得数组上的操作比列表快得多; 此外,阵列占用的内存少于列表。  - 数组为列表索引机制提供强大的扩展。 @@ -216,7 +217,7 @@ print ( 'Time cost of funl is  %f' %cost) ## 创建ndarray -* 我们导入Numpy(在脚本的开头或终端): +* 我们导入Numpy(在脚本的开头或终端): ```python import numpy as np @@ -225,12 +226,12 @@ import numpy as np * 然后我们创建numpy数组: ```python -In [1] : np.array([2, 3, 6, 7])   -Out[l] : array([2, 3, 6, 7])   -In [2] : np.array([2, 3, 6, 7.])   -Out [2] :  array([ 2.,  3.,  6., 7.])  <- Hamogenaous   -In  [3] :  np.array( [2,  3,  6,  7+ij])   -Out [3] :  array([ 2.+O.j,  3.+O.j,  6.+O.j,  7.+1.j]) +In [1]: np.array([2, 3, 6, 7])   +Out[1]: array([2, 3, 6, 7])   +In [2]: np.array([2, 3, 6, 7.])   +Out[2]: array([2., 3., 6., 7.])  <- Hamogenaous   +In [3]: np.array([2, 3, 6, 7+1j])   +Out[3]: array([ 2.+O.j, 3.+O.j, 6.+O.j, 7.+1.j]) ``` @@ -244,12 +245,12 @@ import numpy as np * Then we create numpy arrays:   ```python -In [1] : np.array([2, 3, 6, 7])   -Out[l] : array([2, 3, 6, 7])   -In [2] : np.array([2, 3, 6, 7.])   -Out [2] :  array([ 2.,  3.,  6., 7.])  <- Hamogenaous   -In  [3] :  np.array( [2,  3,  6,  7+ij])   -Out [3] :  array([ 2.+O.j,  3.+O.j,  6.+O.j,  7.+1.j]) +In [1]: np.array([2, 3, 6, 7])   +Out[1]: array([2, 3, 6, 7])   +In [2]: np.array([2, 3, 6, 7.])   +Out[2]: array([ 2., 3., 6., 7.])  <- Hamogenaous   +In [3]: np.array( [2, 3, 6, 7+ij])   +Out[3]: array([ 2.+O.j, 3.+O.j, 6.+O.j, 7.+1.j]) ``` @@ -263,24 +264,23 @@ Out [3] :  array([ 2.+O.j,  3.+O.j,  6.+O.j,  7.+1.j]) * arange: ```python          -in[1]:np.arange(5) -Out [l]:array([0,1,2,3,4]) +In [1]: np.arange(5) +Out[1]: array([0, 1, 2, 3, 4]) ``` range(start, stop, step)的所有三个参数即起始值,结束值,步长都是可以用的 另外还有一个数据的dtype参数  ```python - in[2]:np.arange(10,100,20,dtype = float) - Out [2]:array([10.,30.,50.,70.,90.]) +In [2]: np.arange(10, 100, 20, dtype=float) +Out[2]: array([10., 30., 50., 70., 90.]) ``` -* linspace(start,stop,num)返回数字间隔均匀的样本,按区间[start,stop]计算: +* linspace(start, stop, num)返回数字间隔均匀的样本,按区间[start, stop]计算: ```python - in[3]:np.linspace(0.,2.5,5)         - Out [3]:array([0.,0.625,1.25,1.875,2.5]) - +In [3]: np.linspace(0., 2.5, 5)         +Out[3]: array([0., 0.625, 1.25, 1.875, 2.5]) ``` @@ -297,19 +297,19 @@ range(start, stop, step)的所有三个参数即起始值,结束值,步长 ## 多维数组矩阵 (Matrix by multidimensional array) ```python -In [1] : a = np.array([[l, 2, 3]  [4, 5, 6]]) +In [1]: a = np.array([[l, 2, 3]  [4, 5, 6]])                          ^ 第一行 (Row 1) -In [2] : a -Out [2] : array([[l, 2,  3] ,   [4,  5,  6]]) +In [2]: a +Out[2]: array([[l, 2,  3] ,   [4,  5,  6]]) -In  [3] : a.shape  #<- 行、列数等 (Number of rows, columns etc.) -Out [3] : (2,3) +In [3]: a.shape  #<- 行、列数等 (Number of rows, columns etc.) +Out[3]: (2,3) -In  [4] : a.ndim   #<- 维度数 (Number of dimensions) -Out [4] : 2 +In [4]: a.ndim   #<- 维度数 (Number of dimensions) +Out[4]: 2 -In  [5] : a,size   #<- 元素数量 (Total number of elements) -Out [5] : 6 +In [5]: a,size   #<- 元素数量 (Total number of elements) +Out[5]: 6 ``` @@ -325,11 +325,11 @@ Out [5] : 6 ```python import numpy as np -a = np .arange(0, 20, 1) #1维 -b = a.reshape((4, 5)) #4行5列 -c = a.reshape((20, 1)) #2维 -d = a.reshape((-1, 4)) #-1:自动确定 -#a.shape =(4, 5) #改变a的形状 +a = np .arange(0, 20, 1) # 1维 +b = a.reshape((4, 5)) # 4行5列 +c = a.reshape((20, 1)) # 2维 +d = a.reshape((-1, 4)) # -1:自动确定 +#a.shape = (4, 5) # 改变a的形状 ``` @@ -339,11 +339,11 @@ d = a.reshape((-1, 4)) #-1:自动确定 ``` -## Size(N,),(N,1)和(1,N)是不同的!!! +## Size(N,), (N, 1)和(1, N)是不同的!!! -* Size(N, )表示数组是一维的。 -* Size(N,1)表示数组是维数为2, N列和1行。 -* Size(1,N)表示数组是维数为2, 1行和N列。 +* Size(N, )表示数组是一维的。 +* Size(N, 1)表示数组是维数为2, N列和1行。 +* Size(1, N)表示数组是维数为2, 1行和N列。 让我们看一个例子,如下 @@ -383,15 +383,15 @@ print(c) ## 使用完全相同的元素填充数组 (Filling arrays with identical elements) ```python -In [1] : np.zeros(3)             # zero(),全0填充数组 -Out[l] : array([ O., 0., 0.]) +In [1]: np.zeros(3)             # zero(),全0填充数组 +Out[1]: array([ O., 0., 0.]) -In [2] : np.zeros((2, 2), complex) -Out[2] : array([[ 0.+0.j, 0.+0.j],                +In [2]: np.zeros((2, 2), complex) +Out[2]: array([[ 0.+0.j, 0.+0.j],                [ 0.+O.j, 0.+0.j]]) -In [3] : np.ones((2, 3))         # ones(),全1填充数组 -Out[3] : array([[ 1., 1., 1.], +In [3]: np.ones((2, 3))         # ones(),全1填充数组 +Out[3]: array([[ 1., 1., 1.], [ 1., 1., 1.]]) ``` @@ -408,17 +408,17 @@ Out[3] : array([[ 1., 1., 1.], * rand: 0和1之间均匀分布的随机数 (random numbers uniformly distributed between 0 and 1) ```python   -   In [1] : np.random.rand(2, 4)   - Out[1] : array([[ 0.373767 , 0.24377115, 0.1050342 , 0.16582644] ,  - [ 0.31149806, 0.02596055, 0.42367316, 0.67975249l]) +In [1]: np.random.rand(2, 4)   +Out[1]: array([[0.373767 , 0.24377115, 0.1050342, 0.16582644],  + [0.31149806, 0.02596055, 0.42367316, 0.67975249]]) ``` -* randn: 均值为0,标准差为1的标准(高斯)正态分布 {standard normal (Gaussian) distribution with mean 0 and variance 1}  +* randn: 均值为0,标准差为1的标准(高斯)正态分布 {standard normal (Gaussian) distribution with mean 0 and variance 1}  ```python -  In [2]: np.random.randn(2, 4)  - Out[2]: array([[ O.87747152, 0.39977447, -0.83964985, -1.05129899],  - [-1.07933484, 0.49448873,   -1.32648606, -0.94193424]]) +In [2]: np.random.randn(2, 4)  +Out[2]: array([[0.87747152, 0.39977447, -0.83964985, -1.05129899],  + [-1.07933484, 0.49448873, -1.32648606, -0.94193424]]) ``` * 其他标准分布也可以使用 (Other standard distributions are also available.) @@ -430,37 +430,37 @@ Out[3] : array([[ 1., 1., 1.], -## 数组切片(1D) (Array sliciing(1D)) +## 数组切片(1D) (Array sliciing(1D)) -* 以格式start:stop可以用来提取数组的片段(从开始到不包括stop) +* 以格式start:stop可以用来提取数组的片段(从开始到不包括stop) ```python -In [77]:a = np.array([0,1,2,3,4]) -Out[77]:array([0,1,2,3,4]) +In [77]: a = np.array([0, 1, 2, 3, 4]) +Out[77]: array([0, 1, 2, 3, 4]) -In [78]:a [1:3]       #<--index从0开始 ,所以1是第二个数字,即对应1到3结束,就是到第三个数字,对应是2 -Out[78]:array([1,2]) +In [78]: a [1: 3]       #<--index从0开始 ,所以1是第二个数字,即对应1到3结束,就是到第三个数字,对应是2 +Out[78]: array([1, 2]) ``` * start可以省略,在这种情况下,它被设置为零(Notes:貌似留空更合适): ```python -In [79]:a [:3] -Out[79]:array([0,1,2]) +In [79]: a[:3] +Out[79]: array([0, 1, 2]) ``` * stop也可以省略,在这种情况下它被设置为数组长度: ```python -In [80]:a [1:] -Out[80]:array([1,2,3,4]) +In [80]: a [1:] +Out[80]: array([1, 2, 3, 4]) ``` * 也可以使用负指数,具有标准含义: ```python -In [81]:a [1:-1] -Out[81]:array([1,2,3])     # <-- stop为-1表示倒数第二个数 +In [81]: a [1:-1] +Out[81]: array([1, 2, 3])     # <-- stop为-1表示倒数第二个数 ``` @@ -472,27 +472,27 @@ Out[81]:array([1,2,3])     # <-- stop为-1表示倒数第二个数 -## 数组切片(1D) +## 数组切片(1D) -* 整个数组:a或a [:]   +* 整个数组:a或a[:]   ```python -In [77]:a = np.array([0,1,2,3,4]) -Out[77]:array([0,1,2,3,4]) +In [77]: a = np.array([0, 1, 2, 3, 4]) +Out[77]: array([0, 1, 2, 3, 4]) ``` -* 要获取,例如每个其他元素,您可以在第二个冒号后面指定第三个数字(步骤(step)):   +* 要获取,例如每个其他元素,您可以在第二个冒号后面指定第三个数字(步骤(step)):   ```python -In [79]:a [::2] -Out[79]:array([0,2,4])  +In [79]: a [::2] +Out[79]: array([0, 2, 4])  -In [80]:a [1:4:2] -Out[80]:array([l,3]) +In [80]: a [1:4:2] +Out[80]: array([l, 3]) ``` * -1的这个步骤可用于反转数组: ```python -In [81]:a [::-1] -Out[81]:array([4,3,2,1,0]) +In [81]: a [::-1] +Out[81]: array([4, 3, 2, 1, 0]) ``` @@ -507,21 +507,21 @@ Out[81]:array([4,3,2,1,0]) -## 数组索引(2D)  (Array indexing (2D)) +## 数组索引(2D) (Array indexing (2D)) -* 对于多维数组,索引是整数元组:(For multidimensional arrays, indices are tuples of integers:)  +* 对于多维数组,索引是整数元组:(For multidimensional arrays, indices are tuples of integers:)  ```python -In [93] :  a = np.arange(12) ; a.shape =  (3,  4);  a -Out[93] :  array([[0,  1,  2,  3], +In [93]:  a = np.arange(12) ; a.shape =  (3,  4);  a +Out[93]:  array([[0,  1,  2,  3], [4,  5,  6,  7], [8, 9,  10, 11]]) -In [94] : a[1,2] -Out[94] : 6 +In [94]: a[1,2] +Out[94]: 6 -In [95] : a[1,-1] -Out[95] : 7 +In [95]: a[1,-1] +Out[95]: 7 ``` @@ -537,31 +537,31 @@ Out[95] : 7 -## 数组切片(2D):单行和列 (Array slicing (2D): single rows and columns) +## 数组切片(2D):单行和列 (Array slicing (2D): single rows and columns) -* 索引的工作与列表完全相同:(Indexing works exactly like for lists:) +* 索引的工作与列表完全相同:(Indexing works exactly like for lists:) ```python -In [96] : a = np.arange(12); a.shape = (3, 4); a   -Out[96] : array([[0, 1, 2, 3], - [4, 5, 6, 7], - [8, 9,10,11]]) +In [96]: a = np.arange(12); a.shape = (3, 4); a   +Out[96]: array([[0, 1, 2, 3], + [4, 5, 6, 7], + [8, 9, 10, 11]]) -In [97] : a[:,1] -Out[97] : array([1,5,9]) +In [97]: a[:,1] +Out[97]: array([1,5,9]) -In [98] : a[2,:] -Out[98] : array([ 8, 9, 10, 11]) +In [98]: a[2,:] +Out[98]: array([8, 9, 10, 11]) -In [99] : a[1][2] -Out[99] : 6 +In [99]: a[1][2] +Out[99]: 6 ``` -* 不必明确提供尾随的冒号:(Trailing colons need not be given explicitly:) +* 不必明确提供尾随的冒号:(Trailing colons need not be given explicitly:) ```python -In [100] : a[2] -Out[100] : array([8,9,10,11]) +In [100]: a[2] +Out[100]: array([8, 9, 10, 11]) ``` @@ -609,18 +609,18 @@ array([[20, 22, 24]       * 采用一个NumPy数组的切片可以在原始数组中创建一个视图。 两个数组都指向相同的内存。因此,当修改视图时,原始数组也被修改: ```python -In [30] : a = np.arange(5); a -Out[30] : array([0, 1, 2, 3, 4]) +In [30]: a = np.arange(5); a +Out[30]: array([0, 1, 2, 3, 4]) -In [31] : b = a[2:]; b -Out[31] : array([2, 3, 4]) +In [31]: b = a[2:]; b +Out[31]: array([2, 3, 4]) -In [32] : b[0] = 100 -In [33] : b +In [32]: b[0] = 100 +In [33]: b -Out[33] : array([l00, 3, 4]) -In [34] : a -Out[34] : array([0,1,100,3,4]) +Out[33]: array([100, 3, 4]) +In [34]: a +Out[34]: array([0, 1, 100, 3, 4]) ``` @@ -640,18 +640,18 @@ Out[34] : array([0,1,100,3,4]) * 为避免修改原始数组,可以制作一个切片的副本 (To avoid modifying the original array, one can make a copy of a slice:) ```python -In [30] : a = np.arange(5); a -Out[30] : array([0, 1, 2, 3, 4]) +In [30]: a = np.arange(5); a +Out[30]: array([0, 1, 2, 3, 4]) -In [31] : b = a[2:].copy(); b -Out[31] : array([2, 3, 4]) +In [31]: b = a[2:].copy(); b +Out[31]: array([2, 3, 4]) -In [32] : b[0] = 100 -In [33] : b -Out[33] : array([1OO, 3, 4]) +In [32]: b[0] = 100 +In [33]: b +Out[33]: array([1OO, 3, 4]) -In [34] : a -Out[34] : array([ 0,  1.  2,  3,  4]) +In [34]: a +Out[34]: array([0, 1, 2, 3, 4]) ``` @@ -679,7 +679,7 @@ Out[3]: array([[1, 4], [9, 16]]) ``` -* 使用dot()函数进行矩阵乘法:(Matrix multiplication is done with the dot() function:) +* 使用dot()函数进行矩阵乘法:(Matrix multiplication is done with the dot() function:) ```python @@ -697,19 +697,19 @@ Out[4]: array([[ 7, 10], ## 矩阵乘法 -* dot()方法也适用于矩阵向量(matrix-vector)乘法: +* dot()方法也适用于矩阵向量(matrix-vector)乘法: ```python In [1]: A -Out[1]: array([[1, 2],[3, 4]]) +Out[1]: array([[1, 2], [3, 4]]) In [2]: x = np.array([10, 20]) In [3]: np.dot(A, x) -Out[3]: array([ 50, 110]) +Out[3]: array([50, 110]) In [4]: np.dot(x, A) -Out[4]: array([ 70, 100]) +Out[4]: array([70, 100]) ``` @@ -725,13 +725,13 @@ Out[4]: array([ 70, 100]) *  savetxt()将表保存到文本文件。 (savetxt() saves a table to a text file.)     ```python     -In  [1]: a = np,linspace(0. 1, 12); a,shape ' (3, 4); a -Out [1] : -array([[ O.  ,  0.09090909, 0.18181818,  0.27272727], -[  0.36363636,  0.45454545, 0.54545455,  0.63636364], -[  0.72727273,  0.81818182. 0.90909091,  1.]]) +In [1]: a = np.linspace(0, 1, 12); a,shape = (3, 4); a +Out[1]: +array([[0. ,  0.09090909, 0.18181818, 0.27272727], +[0.36363636, 0.45454545, 0.54545455, 0.63636364], +[0.72727273, 0.81818182, 0.90909091, 1.]]) -In [2] : np.savetxt("myfile.txt", a) +In [2]: np.savetxt("myfile.txt", a) ``` @@ -740,11 +740,11 @@ In [2] : np.savetxt("myfile.txt", a) * save()将表保存为Numpy“.npy”格式的二进制文件 (save() saves a table to a binary file in NumPy ".npy" format.)  ```python    - - In [3] : np.save("myfile" ,a)    +In [3]: np.save("myfile", a)    ``` -  - 生成一个二进制文件myfile .npy,其中包含一个可以使用np.load()加载的文件。 {produces a binary file myfile .npy that contains a and that can be loaded with np.load().} +  - 生成一个二进制文件myfile .npy,其中包含一个可以使用np.load()加载的文件。 {produces a binary file myfile .npy that contains a and that can be loaded with np.load().} @@ -761,9 +761,9 @@ In [2] : np.savetxt("myfile.txt", a) ## 将文本文件读入数组 (Reading text files into arrays) -* loadtxt()将以文本文件存储的表读入数组。 (loadtxt() reads a table stored as a text file into an array.) +* loadtxt()将以文本文件存储的表读入数组。 (loadtxt() reads a table stored as a text file into an array.) -* 默认情况下,loadtxt()假定列是用空格分隔的。 您可以通过修改可选的参数进行更改。 以散列(#)开头的行将被忽略。 (By default, loadtxt() assumes that columns are separated with whitespace. You can change this by modifying optional parameters. Lines starting with hashes (#) are ignored.) +* 默认情况下,loadtxt()假定列是用空格分隔的。 您可以通过修改可选的参数进行更改。 以散列(#)开头的行将被忽略。 (By default, loadtxt() assumes that columns are separated with whitespace. You can change this by modifying optional parameters. Lines starting with hashes (#) are ignored.) * 示例文本文件data.txt: (Example text file data.txt:) @@ -777,11 +777,11 @@ In [2] : np.savetxt("myfile.txt", a) * Code: ```python  - In [1] : tabla = np.loadtxt("data.txt") -   In [2] : table -   Out[2] : -   array ([[ 1.99000000e+03,   -1.50000000e+00,   2.53000000e+01],    - [ 1.9910000e+03,  -3.2000000e+00,  2.12000000e+01] +In [1]: tabla = np.loadtxt("data.txt") +In [2]: table +Out[2]: +array([[1.99000000e+03, -1.50000000e+00, 2.53000000e+01],  +[1.9910000e+03, -3.2000000e+00, 2.12000000e+01]]) ``` @@ -859,7 +859,7 @@ print(det)           ``` -* linalg的其他有用的方法:eig()(特征值和特征向量),det()(行列式)。{Other useful functions from linalg: eig() (eigenvalues and eigenvectors), det() (determinant). }  +* linalg的其他有用的方法:eig()(特征值和特征向量),det()(行列式)。{Other useful functions from linalg: eig() (eigenvalues and eigenvectors), det() (determinant). }  @@ -905,13 +905,13 @@ print(error) from scipy import stats ``` -* 然后您可以使用一些有用的统计功能。 例如,给出标准正态分布的累积密度函数(Then you are able to use some useful statistical function. For example, the cummulative density function of a standard normal distribution is given like +* 然后您可以使用一些有用的统计功能。 例如,给出标准正态分布的累积密度函数(Then you are able to use some useful statistical function. For example, the cummulative density function of a standard normal distribution is given like ![Statistics-in-Scipy](https://github.com/MurphyWan/Python-first-Practice/blob/master/images/3days_img010_statistics_in_scipy.jpg) -* 这个包,我们可以直接使用它,如下: (with this package, we can directly use it like) +* 这个包,我们可以直接使用它,如下: (with this package, we can directly use it like) ```python from scipy import stats @@ -1225,9 +1225,9 @@ plt.title('3D plot of $z = x^2 + y^2$')  ![1](https://github.com/MurphyWan/Python-first-Practice/blob/master/images/3days_img017_1.jpg) - - 然后用红点标记坐标(1,2) (Then mark the coordinate (1, 2) with a red point.) + - 然后用红点标记坐标(1,2) (Then mark the coordinate (1, 2) with a red point.) -* 使用np.linspace()使t ∈ [0,2π]。 然后给 (Use np.linspace0 to make t ∈ [0,2π]. Then give) +* 使用np.linspace()使t ∈ [0, 2π]。 然后给 (Use np.linspace0 to make t ∈ [0,2π]. Then give)   ![2](https://github.com/MurphyWan/Python-first-Practice/blob/master/images/3days_img017_2.jpg) @@ -1293,12 +1293,12 @@ plt.title('3D plot of $z = x^2 + y^2$') import sympy as sy -#声明x,y为变量 +#声明x,y为变量 x = sy.Symbol('x') y = sy.Symbol('y') a, b = sy.symbols('a b') -#创建一个新符号(不是函数 +#创建一个新符号(不是函数 f = x**2 + 2 - 2*x + x**2 -1 print(f) #自动简化 @@ -1393,4 +1393,3 @@ print(sy.diff (g,  y)) ![](http://upload-images.jianshu.io/upload_images/5522220-cd6a23ee687856ca.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) [传送门-> 第三天的内容](https://github.com/MurphyWan/Python-first-Practice/blob/master/D3_of_3Day_DoneWithPython.md) -